@floorlaunchpad/sdk 0.3.2 → 0.4.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.md +16 -0
  3. package/dist/abi/evm.gen.js +6 -1
  4. package/dist/abi/solana.gen.js +1 -1
  5. package/dist/client/evm/index.js +16 -2
  6. package/dist/client/solana/index.js +31 -14
  7. package/dist/config/generated.js +26864 -402
  8. package/dist/config/registry.gen.js +33 -2
  9. package/dist/evm/chains.js +85 -16
  10. package/dist/evm/floor/abi.gen.js +1 -1
  11. package/dist/evm/floor/events.js +9 -1
  12. package/dist/evm/floor/legacy-events.js +25 -0
  13. package/dist/evm/router.js +25 -1
  14. package/dist/evm/squid.js +9 -9
  15. package/dist/evm/zap.js +148 -35
  16. package/dist/indexer/bodies.js +96 -17
  17. package/dist/indexer/client.js +36 -14
  18. package/dist/indexer/contract.js +178 -28
  19. package/dist/indexer/partners.js +3 -2
  20. package/dist/indexer/paths.js +87 -29
  21. package/dist/indexer/read.js +30 -15
  22. package/dist/indexer/search.js +130 -0
  23. package/dist/indexer/stack-edge.js +35 -0
  24. package/dist/indexer/stream.js +70 -23
  25. package/dist/math/v2/split.js +11 -3
  26. package/dist/solana/floor/events.js +1 -1
  27. package/dist/solana/floor/genesis.js +9 -3
  28. package/dist/solana/floor/instructions.js +14 -5
  29. package/dist/solana/floor/registry.js +4 -0
  30. package/dist/v2/devbuy.js +6 -4
  31. package/dist/v2/presetRowEvm.js +21 -2
  32. package/dist/v2/solana.js +17 -2
  33. package/dist/v2/tx/solana.js +1 -1
  34. package/docs/aggregator.md +22 -0
  35. package/docs/bot.md +44 -1
  36. package/docs/cursor-pages.md +58 -0
  37. package/docs/floor-line.md +9 -4
  38. package/docs/frontend.md +2 -0
  39. package/docs/wallet.md +2 -0
  40. package/examples/floor-line.html +6 -6
  41. package/package.json +1 -1
  42. package/src/abi/evm.gen.ts +6 -1
  43. package/src/abi/solana.gen.ts +1 -1
  44. package/src/client/evm/index.ts +16 -2
  45. package/src/client/solana/index.ts +31 -14
  46. package/src/client/types.ts +1 -1
  47. package/src/config/generated.ts +26864 -402
  48. package/src/config/index.ts +9 -2
  49. package/src/config/registry.gen.ts +33 -2
  50. package/src/events/types.gen.ts +2 -1
  51. package/src/evm/chains.ts +94 -15
  52. package/src/evm/floor/abi.gen.ts +1 -1
  53. package/src/evm/floor/events.ts +11 -1
  54. package/src/evm/floor/legacy-events.ts +27 -0
  55. package/src/evm/router.ts +26 -1
  56. package/src/evm/squid.ts +9 -9
  57. package/src/evm/zap.ts +185 -36
  58. package/src/indexer/bodies.ts +106 -17
  59. package/src/indexer/client.ts +56 -30
  60. package/src/indexer/contract.ts +197 -29
  61. package/src/indexer/partners.ts +3 -2
  62. package/src/indexer/paths.ts +131 -29
  63. package/src/indexer/read.ts +36 -17
  64. package/src/indexer/search.ts +138 -0
  65. package/src/indexer/stack-edge.ts +46 -0
  66. package/src/indexer/stream.ts +78 -24
  67. package/src/math/v2/split.ts +11 -3
  68. package/src/solana/floor/events.ts +1 -1
  69. package/src/solana/floor/genesis.ts +8 -2
  70. package/src/solana/floor/instructions.ts +13 -5
  71. package/src/solana/floor/registry.ts +4 -0
  72. package/src/v2/devbuy.ts +6 -4
  73. package/src/v2/presetRowEvm.ts +21 -2
  74. package/src/v2/solana.ts +20 -3
  75. package/src/v2/tx/solana.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,100 @@
2
2
 
3
3
  All notable changes to `@floorlaunchpad/sdk`. The version follows semver; while the major number is 0, a minor bump may rename or remove an export and a patch bump never does.
4
4
 
5
+ ## 0.4.1
6
+
7
+ Fixed:
8
+
9
+ - `zapSwapData` appends `SWEEP(address(0), MSG_SENDER, 0)` to a native-input Universal Router swap (Uniswap, Aerodrome, Pancake and Ramses forks, V2 / V3 and v4). A Squid hook forwards the whole bridged amount as the zap's value, the plan spent only `amountIn`, and the surplus stayed on the router for anyone to sweep; it now returns to the zap, which refunds it. Token-in and native-out routes, and every non-Universal-Router family, encode the same bytes as before.
10
+ - `zapSwapData` encodes a zap whose input is an ERC-20 (`buyWithToken`) and whose output is the native coin (a launch quoted in the native coin). Before, every route began with `WRAP_ETH` (or a native-only call) and paid the router's output in its wrapped form, so an ERC-20 → native-coin zap through a Universal Router, a V3 SwapRouter, SwapRouter02 or Algebra router reverted (`QuoteShort`; measured on forks of every zap row). New optional params: `input` ("native", the default, or "token"), `output` ("token", the default, or "native": the router unwraps and pays the zap, which accepts the native coin only from its router), and `router` (a SwapRouter v1 native output is paid to the router, then unwrapped). The defaults encode the same bytes as before.
11
+ - The Universal Router forks' swap input: `urFork` ("uniswap", the default, "aerodrome", "pancake" or "ramses"; each fork row in `EVM_CHAINS` names its own as `urFork`). Aerodrome's router reads a sixth `bool isUni` (sent false: its Slipstream pools, each key `0x100000 | tickSpacing`, `AERODROME_SLIPSTREAM_KEY`); PancakeSwap's and Ramses' read five fields. Before, every fork got Uniswap's sixth `uint256[]`, which Aerodrome's router reads as `isUni = true` and routes through Uniswap's pools instead of its own. A V2 leg through a fork's router is refused (its input is its own).
12
+ - `buyHookNative` (the Squid postHook that buys through the zap with a bridged native coin) takes the launch's `quote` and, when it is an ERC-20, adds a third call that passes the zap's quote refund on to `user` (`FullTokenBalance quote.transfer(user, FULL)`). Before, the unspent quote the program paid back stayed on the multicall, where anyone could sweep it. `quote` is optional: absent or address(0) (a launch quoted in the native coin), the hook is the same two calls as 0.4.0, byte for byte, so a 0.4.0 call still compiles and encodes as before; pass the ERC-20 quote to get the refund call.
13
+ - `devBuyFromTrade` takes an optional `ctx.buyer`: the person a known zap's or router's own event proves for a buy through it. A buy through the zap or the router has the contract as the trade's `trader`, so a creator's or team member's buy through either was not named a dev buy; with `ctx.buyer` it is, and the returned `trader` is that person. The trade's recipient alone never names one (anyone can buy with the creator as recipient).
14
+ - `EVM_ERRORS` and `decodeEvmProgramError` now know five errors the v2 contracts revert with from their math libraries, which the contracts' ABI does not list: `PriceOrder()`, `ZeroLiquidity()`, `SqrtRange()`, `Zero()` and `VaultShareOutOfRange()`. Before, a revert with one of them decoded as unknown; now it decodes by its selector like any other EVM error.
15
+ - `zapSwapData` now refuses a route that names address(0) (the wrapped native stands for the native coin) or swaps a coin into itself (neither names a pool a router can trade).
16
+
17
+ Added:
18
+
19
+ - `FLOOR_ZAP_ADDRESSES`: the deployed FloorZap instance address per chain and zap slot (15 instances on 8 chains, Elysium's `uniswap-ur` included; one address per slot on every chain that has it), and `zap` on each `EVM_CHAINS` zap row (the instance to call, or `null` where that slot is not deployed). A wallet or an integrator no longer needs its own copy of the zap addresses.
20
+ - Elysium's zap: `EVM_CHAINS.elysium.zapRouters` holds Uniswap's Universal Router 2.1.2 (`0xA13f7611115752DEB2B13813BDDE16A5073e4b45`, slot `uniswap-ur`) with its deployed zap booked (`FLOOR_ZAP_ADDRESSES.elysium`, the same `uniswap-ur` address as every other chain: 15 zaps in all), and `wrappedNative` is WHYPE (`0xbA876237B0F021A6c6D852d6c26E107997cC5E81`, 18 decimals). Elysium's depth is in Uniswap v4 only (native HYPE / USDC pools), so its zap routes through the v4 route below, never through WRAP_ETH.
21
+ - `zapSwapData` encodes Uniswap v4 through the Universal Router: one pool, exact in, given as `route.v4` (`ZapV4Pool`: fee, tick spacing, hooks, hook data) with `route.tokens` = [currency in, currency out] and `V4_NATIVE` (address(0)) for the native coin. The calldata is `V4_SWAP` with `SWAP_EXACT_IN_SINGLE`, `SETTLE` (paid by the router: the zap pays an ERC-20 input to it first; a native input rides as the call's value) and `TAKE`; a native output is taken to the router and then swept to the zap (`SWEEP`, at the same minimum), since the zap accepts the native coin only from its router. New beside it: `v4PoolKey` (the sorted pool key and the swap's direction), the type `V4PoolKey`, and the constants `UR_V4_SWAP`, `V4_SWAP_EXACT_IN_SINGLE`, `V4_SETTLE`, `V4_TAKE`, `V4_OPEN_DELTA` and `V4_NATIVE`. A route without `v4` encodes as before.
22
+ - Indexer batched reads: `floor-amm/launch-lists` (`indexerPath.launchLists`, `readLaunchLists`, body `LAUNCH_LISTS`) returns one `launches?quote=` page per asked quote in one request, each list resumed with its own cursor (`LAUNCH_LISTS_FIRST` asks a first page; at most `LAUNCH_LISTS_QUOTES_MAX` quotes and `LAUNCH_LISTS_ROWS_MAX` rows); `floor-amm/candles/many` (`indexerPath.candlesMany`, `readCandlesMany`, body `CANDLES_MANY`) returns many launches' newest candles at one interval in one request (at most `CANDLES_MANY_IDS_MAX` launches, `missing` names the unknown ones). Both are in `INDEXER_CONTRACT` and the client; against an indexer that does not serve them the readers throw `IndexerError`.
23
+ - `readPresetMenuEvmV2` reads the preset rows through one Multicall3 `aggregate3` per 100 ids (1 + ⌈K ÷ 100⌉ calls instead of 1 + K); a failed row throws, never a gap in the menu. New optional third argument `{ multicall }`: another Multicall3 address, or `null` to send one `presetRow` call per id on a chain without Multicall3.
24
+ - The Solana client's `claim` reads its launches side by side instead of one after another: the round trips no longer grow with the number of launches (5 launches: 15 round trips to 3). Same transaction, same refusals; the quote's fields still come from the last launch asked.
25
+ - FloorRouter addresses: `FLOOR_ROUTER_ADDRESSES` (per chain and zap slot), `floorRouter` on each `EVM_CHAINS` zap row, `FLOOR_ROUTER_DEPLOYER` and `floorRouterAddress(slot)`. One address per slot, the same on every chain that has it (7 routers over the 15 zap rows). The addresses are derived ahead of the routers' deploy, not read back from chain: each is usable only once it has code on that chain. A call to one with no code still succeeds and buys nothing, and a native-in buy's coin sent to it stays at that empty address and is lost. `floorRouterLive` and `assertFloorRouterLive` (`evm/router`) check the code through your `getCode` ("0x" or `undefined` is no code); check before you build a call to one, as `evmRouteCallV2` itself reads no chain.
26
+
27
+ Changed:
28
+
29
+ - Elysium is switched on: its chain registry row is no longer `v2DayOne: false`, so `v2DayOneChains()` now includes Elysium (eight EVM chains). Elysium is live at the same address as the other EVM chains.
30
+
31
+ Added (to carry the fixes; nothing removed or renamed): the type `ZapUrFork`, the constant `AERODROME_SLIPSTREAM_KEY`, the optional `ZapSwapParams` keys `input`, `output`, `router` and `urFork`, and the optional `urFork` on each `EVM_CHAINS` zap row.
32
+
33
+ ## 0.4.0
34
+
35
+ Removed:
36
+
37
+ - `LAUNCHES_ALL` (the body of `floor-amm/launches` with no query key). No request answers every launch any more: a bare
38
+ `floor-amm/launches` is one page, decoded by `LAUNCHES`.
39
+
40
+ Changed:
41
+
42
+ - `INDEXER_CONTRACT.launches`: the default `limit` is `LAUNCHES_PAGE_DEFAULT` (100, was 1000); the page kind is the new
43
+ `keyset` (`Pagination` gains `{ kind: "keyset", limit, cursor: "cursor", next: "next" }`); the keys gain `preset` and
44
+ `cursor` (`cursor` not with `offset` or `ids`).
45
+ - `LAUNCHES` (the list body) gains `cursors` (the cursor after each row), `keys` (each row's ranked key as a decimal
46
+ string, null in the unread tail) and `next` (the last cursor while rows remain, else null). `cursors` and `keys` are []
47
+ with `ids` or `offset`; an indexer without them decodes with `cursors` / `keys` [] and `next` absent.
48
+ - A `string` query key's `max` bounds the raw length as sent; a `list` key may bound each item (`item`); `required` is
49
+ refused by the table on `search` only.
50
+ - `drain("launches")` follows `next` as `cursor` (by `total` with `offset`).
51
+
52
+ - The six wallet routes page on request: `positions`, `walletLocks`, `claimHistory`, `people` and `roles` take `limit`
53
+ (default `WALLET_PAGE_DEFAULT` 100, at most `WALLET_PAGE_MAX` 500) and `cursor` (opaque, at most `WALLET_CURSOR_MAX`
54
+ characters) and answer `next`; `inbox` takes `before` (`""` the newest; default `INBOX_PAGE_DEFAULT` 100, at most
55
+ `INBOX_PAGE_MAX` 500) and answers `next`. With neither key each answers every row, as before. Their decoders
56
+ (`POSITIONS`, `WALLET_LOCKS`, `CLAIM_HISTORY`, `PEOPLE`, `ROLES`, `INBOX`) gain an optional `next`; the readers
57
+ (`readPositions`, `readWalletLocks`, `readClaimHistory`, `readPeople`, `readRoles`, `readInbox`) take the page keys.
58
+ - Four more routes page, with a page of 100 rows when no key is sent: `floorRouted` (`limit` up to `LAUNCHES_PAGE_MAX`
59
+ 1,000, `cursor` the last launch id, create order; `pending` stays the whole per-quote sum on every page), `devBuys`
60
+ (`limit` up to 500, `before` a block or a row id, newest first), `claimView` (`limit` up to `WALLET_PAGE_MAX` 500,
61
+ `cursor` the last row key: `l:<launch>`, `r:<account>`, `p:<traderRef>` or `o:<quote>`; `quotes` and `totals` stay
62
+ whole) and `handlePlaces` (`limit` up to 500, `cursor` `<launch>:<place>`). Each body (`FLOOR_ROUTED`, `DEV_BUYS`,
63
+ `CLAIM_VIEW`, `HANDLE_PLACES`) gains an optional `next`, null on the last page; `indexerPath`, `routePath` and the readers
64
+ (`readDevBuys`, `readClaimView`, `readHandlePlaces`) take the page keys, and `DRAIN_NAMES` gains the four.
65
+ - **Breaking:** a `DEV_BUY` row carries a required `id` (`<block>:<txnIndex>:<eventIndex>`, the `before` cursor). This
66
+ build's decoder refuses a dev-buys body from an indexer older than it, which sends rows without `id`.
67
+ - A candle (`readCandles`, `floor-amm/candles` and the candle bundle) gains `floorX64`: the floor at the bucket's close, a
68
+ Q64.64 price as a launch's own `floorX64`. It is absent from an indexer older than this build and null where the bucket
69
+ has none.
70
+ - `DEX_PAIR`: the pair gains `dexKey`, `createdAtTxnId` (optional) and `creator`; the body gains an optional `launch`
71
+ (`{ id, token }`), so a pair resolves to its launch in one read.
72
+ - **Breaking:** `roles.traderRefOf[].tier` is 1-based (1..3), as `creatorRefOf`'s; it was 0-based. A client that
73
+ added 1 to show a tier must stop.
74
+
75
+ Added:
76
+
77
+ - Indexer: the route `GET /floor-amm/search?q=` (also under `/floor-amm/v2/`; `INDEXER_CONTRACT.search`,
78
+ `indexerPath.search`, reader `search`, `readLaunchSearch`, decoder `LAUNCH_SEARCH`, type `LaunchSearch`): launches whose
79
+ symbol, name or token match, best first, each row with its `tier` (0..4), keyset pages by `next`; keys `q`, `limit`
80
+ (default `SEARCH_PAGE_DEFAULT` 12, at most `SEARCH_PAGE_MAX` 100), `cursor`, `rankable`, `graduated`, `quote`, `preset`.
81
+ - `src/indexer/search.ts`: `searchFold`, `searchNeedle`, `searchNeedles` (a query with a leading `$` has two readings,
82
+ without and with it; its tier is the better), `searchTier`, `searchTierFolded`, `searchServed`, `searchServedTier`,
83
+ `SEARCH_PARITY_CORPUS`, `SEARCH_Q_MAX`, `SEARCH_PAGE_DEFAULT`, `SEARCH_PAGE_MAX`, `ADDRESS_PREFIX_MIN`,
84
+ `SEARCH_SUBSTRING_MIN`; `paths.ts`: `LAUNCHES_PAGE_DEFAULT`, `LAUNCH_CURSOR_MAX`, `PRESET_FILTER_MAX`, the `preset` and
85
+ `cursor` keys of `LaunchesQuery`, `LaunchSearchQuery`.
86
+ - `cursorPage` / `CursorPage` (one `{ rows, next }` off any page body), `pageAsked`, `pageLimit`, the type `WalletPage`.
87
+ - Indexer (TON only): `GET /floor-amm/wallets/<wallet>/ton-activity` (`limit` ≤ 200, `before`; `INDEXER_CONTRACT.tonActivity`, `indexerPath.tonActivity`, reader `readTonActivity`, decoder `TON_ACTIVITY` / `TON_ACTIVITY_ROW`) and `GET /floor-amm/wallets/<wallet>/ton-outcome?queryId=` (`tonOutcome`, `readTonOutcome`, `TON_OUTCOME`): a TON wallet's recent FLOOR events, and one pending / landed / failed outcome with its fill by the message's query id. Other chains answer `unknown route`.
88
+ - TON (repository source only, not in the published package): `getTeamSlot` (`get_team_slot`, places decoded and ordered), `getPresetRow` (`get_preset_row`, typed result), `parseRefMap` / `decodeTonSlotPlace`, and `defaultClaimValue` exported from the barrel.
89
+ - TON (repository source only, not in the published package): the price write: `tonPriceCell`, `tonPriceDigest`, `tonSetQuotePriceBody`, `buildTonSetQuotePrice`, `tonQuotePriceFresh` (`TON_PRICE_WINDOW_S`, `TON_PRICE_AHEAD_CAP_S`, `TON_PRICE_WRITE_VALUE`, type `TonPriceArgs`), `getTonQuotePrice` (type `TonQuotePrice`); `addressItem` and `getQuote` take `null` (the GRAM quote).
90
+ - Chains: `elysium` (Elysium, chain 99901, native HYPE; Kinetiq's Arbitrum Orbit L2 on HyperEVM) in the chain registry,
91
+ `EVM_CHAINS` and the config rows, marked `v2DayOne: false` (an added chain, not v2 day one): `v2DayOneChains()` still
92
+ returns the seven, `FLOOR_AMM_FROM_BLOCK.elysium` is 6058368 (no code at block 6058367; the live proxy has code from 6058368), no zap routers and no wrapped native yet.
93
+ - Elysium is live: FLOOR is deployed on Elysium 99901 at the same address as the other EVM chains, and the config now lists stock quotes (`deploy/config/quotes/elysium.json`).
94
+
95
+ Fixed:
96
+
97
+ - TON `fromBoc`: a BoC whose data ends in a zero completion byte no longer loops forever, and a truncated, oversized-count or out-of-range one throws a `RangeError` (never `undefined`, never a partial cell).
98
+
5
99
  ## 0.3.2
6
100
 
7
101
  Added:
package/README.md CHANGED
@@ -27,6 +27,7 @@ Node 22.18 or newer. The package ships compiled JavaScript in `dist/` with the t
27
27
  | An aggregator or router | [docs/aggregator.md](docs/aggregator.md): find a route, quote it, build the Solana instructions or the EVM call |
28
28
  | A wallet | [docs/wallet.md](docs/wallet.md): decode what a transaction does, read errors, build a claim |
29
29
  | A bot or indexer | [docs/bot.md](docs/bot.md): read launches, follow the stream, decode logs |
30
+ | Anyone paging an indexer list | [docs/cursor-pages.md](docs/cursor-pages.md): which key each route pages by, the defaults and the limits |
30
31
  | A frontend | [docs/frontend.md](docs/frontend.md): the root entry, the indexer readers, the math for display |
31
32
  | Anyone who shows a FLOOR token: chart, screener, terminal, wallet | [docs/floor-line.md](docs/floor-line.md): show the FLOOR line and the FLOOR price (the one ask) |
32
33
 
@@ -38,6 +39,8 @@ A launch's floor is the price the program's own money stands behind. Drawing it
38
39
 
39
40
  The version follows semver. While the major number is 0, a minor bump (0.2 to 0.3) may rename or remove an export and a patch bump never does. The plan and the history are in [CHANGELOG.md](CHANGELOG.md).
40
41
 
42
+ 0.4.1 adds, without renaming or removing anything: the deployed zap addresses (`FLOOR_ZAP_ADDRESSES`, `zap` on each zap row) and more `zapSwapData` routes ([aggregator.md](docs/aggregator.md)), batched indexer reads (`readLaunchLists`, `readCandlesMany`, [bot.md](docs/bot.md)), a batched EVM preset menu ([frontend.md](docs/frontend.md)), five more decoded EVM errors ([wallet.md](docs/wallet.md)) and an optional `ctx.buyer` for `devBuyFromTrade`.
43
+
41
44
  **Fees in a quote.** A quote's `fees` has the five fee legs, each added on top of the trade, buys and sells alike: the
42
45
  Backing Fee (`backing`), the Team Fee (`team`), the Platform fee (`platform`), the $FLOOR fee (`floor`) and the Holder Fee
43
46
  (`holder`), with their `total`. Any leg can be 0. Before graduation a preset launch pays only the Platform fee and the
@@ -45,6 +48,14 @@ $FLOOR fee; the other three start at graduation. The rates are the launch's own,
45
48
  the quote rather than from a table. Marketcap Milestones are not fees: they sit inside the price, are paid only by buys on
46
49
  the way up and never appear in `fees`.
47
50
 
51
+ **TON.** The TON module (`src/ton`, see `docs/ton.md`) builds the messages for the FLOOR program on TON, reads its state (`getTeamSlot`, `getPresetRow`, `simBuy`, `simSell`) and parses the book file. It is repository source only: the published package does not export `/ton`.
52
+
53
+ **Governance actions on TON.** `src/ton/governance.ts` decodes the body of every governance message on TON (the
54
+ timelock's `schedule` / `execute` / `cancel`, and every authority, timelock and upgrade op of the factory and a launch) into
55
+ the op, its target, every field (amounts with their decimals, code hashes, a scheduled action decoded too) and plain text
56
+ lines, so a multisig shows exactly what is signed before anyone signs. It refuses an unknown op, a truncated body, or a bit
57
+ or a reference left over, rather than show part of a body. `buildTonGovBody` builds the same bodies; neither signs nor sends.
58
+
48
59
  **Reading an indexer.** `@floorlaunchpad/sdk/indexer/read` has one reader per indexer route and a decoder for each body. The SDK opens no connection and names no host. You pass a `Get`, a function from a path such as `/floor-amm/launches/<id>` to `{ status, body }`, and it can be `fetch` against your own indexer, a proxy, or a cache:
49
60
 
50
61
  ```ts
@@ -60,6 +71,11 @@ const page = await readTrades(get, launch.id, { limit: 50 });
60
71
  const older = page.next === null ? null : await readTrades(get, launch.id, { limit: 50, before: page.next });
61
72
  ```
62
73
 
74
+ Lists come in pages. `readLaunches` answers 100 launches a page, and no request answers them all. `readLaunchSearch`
75
+ finds launches by symbol, name or token. The wallet lists, such as `readPositions` and `readClaimHistory`, page when you
76
+ ask with `limit` or `cursor`. Each page carries `next`, and [docs/cursor-pages.md](docs/cursor-pages.md) says which key
77
+ takes it back on each route. `readCandles` returns each candle with `floorX64`, the floor at that candle's close.
78
+
63
79
  Amounts come back as `bigint`. A non-200 answer throws an `IndexerError`: `notReady` while the indexer is still catching up to the chain, `unknownLaunch` for an id it does not know. A body of the wrong shape throws a `ShapeError` naming the field. `@floorlaunchpad/sdk/indexer/stream` parses the live stream's frames in the same way, and `indexerPath` builds any route's path if you want to do the request yourself.
64
80
 
65
81
  **Launch ids.** FLOOR has no pool: a launch trades against the program. On EVM it is FloorAmm's `launchId` (a uint256, written as its decimal string); on Solana it is the address of the `Launch` account. Every launch read (the `LaunchId` type) takes either that id or the launch's token address, and both name the same launch. The answer names the launch by its id: `launch.id` on a launch read, `launch` on each row elsewhere. The transaction builders take the id itself, so look a token up with `readLaunch` before you build a trade.
@@ -8,7 +8,7 @@ export const EVM_EVENT_SCHEMAS = [
8
8
  { name: "TokensBurnedV2", signature: "TokensBurnedV2(uint256,address,uint8,uint8,uint256,uint256,uint256,uint256,uint256[10],uint256,uint256,uint256,uint256)", topic: "0xf6e435381411d86653aa1fb249000f3ead53faa462387a4492da7021bb1ed930", params: [{"name":"launchId","type":"uint256","indexed":true},{"name":"wallet","type":"address","indexed":true},{"name":"role","type":"uint8","indexed":false},{"name":"place","type":"uint8","indexed":false},{"name":"fromTeamBuy","type":"uint256","indexed":false},{"name":"fromWallet","type":"uint256","indexed":false},{"name":"balanceBefore","type":"uint256","indexed":false},{"name":"owedAfter","type":"uint256","indexed":false},{"name":"split","type":"uint256[10]","indexed":false},{"name":"supply","type":"uint256","indexed":false},{"name":"sOut","type":"uint256","indexed":false},{"name":"floorAfterX64","type":"uint256","indexed":false},{"name":"fromShareBought","type":"uint256","indexed":false}] },
9
9
  { name: "OptedIn", signature: "OptedIn(address)", topic: "0x25f9c685db8e2630204f5e7c890a95f58852ccac883a9d96f44a72b777b06c59", params: [{"name":"a","type":"address","indexed":true}] },
10
10
  { name: "ClaimSkipped", signature: "ClaimSkipped(address,address,uint256)", topic: "0x4db58311c6a38618cc6dd27586cfb08657be781d572fb89d63886e3a04b654fa", params: [{"name":"wallet","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"amount","type":"uint256","indexed":false}] },
11
- { name: "Claimed", signature: "Claimed(address,address,address,uint8,uint256,uint256,uint256,uint256,uint256,uint256,uint256)", topic: "0x586c69c7198e9e5c48c058d0267bd1388a73f9a8878aeb9d72d25331acc39aeb", params: [{"name":"wallet","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"types","type":"uint8","indexed":false},{"name":"creator","type":"uint256","indexed":false},{"name":"creatorRef","type":"uint256","indexed":false},{"name":"teamSlot","type":"uint256","indexed":false},{"name":"traderRef","type":"uint256","indexed":false},{"name":"holder","type":"uint256","indexed":false},{"name":"extra","type":"uint256","indexed":false},{"name":"amount","type":"uint256","indexed":false}] },
11
+ { name: "Claimed", signature: "Claimed(address,address,address,uint16,uint256,uint256,uint256,uint256,uint256,uint256,uint256)", topic: "0xc65b75258efd65cacbab47f067226591f78c24d2ee3c3deedf737ca24dc84ada", params: [{"name":"wallet","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"types","type":"uint16","indexed":false},{"name":"creator","type":"uint256","indexed":false},{"name":"creatorRef","type":"uint256","indexed":false},{"name":"teamSlot","type":"uint256","indexed":false},{"name":"traderRef","type":"uint256","indexed":false},{"name":"holder","type":"uint256","indexed":false},{"name":"extra","type":"uint256","indexed":false},{"name":"amount","type":"uint256","indexed":false}] },
12
12
  { name: "ConfigWritten", signature: "ConfigWritten(address,address,address,address,bool,address)", topic: "0x8f06444aa7d0507d408688b0ec6fc465e012cf24967de8b2205cfd16fcb4566d", params: [{"name":"authority","type":"address","indexed":false},{"name":"pendingAuthority","type":"address","indexed":false},{"name":"timelock","type":"address","indexed":false},{"name":"referralAuthority","type":"address","indexed":false},{"name":"createPaused","type":"bool","indexed":false},{"name":"holderDest","type":"address","indexed":false}] },
13
13
  { name: "CreatorBuyUnlocked", signature: "CreatorBuyUnlocked(uint256,address,uint256,uint256[10],uint256)", topic: "0x39c11edf00e81e75225d0fc2b6f83cabd8ba915d7a071fa450cfb032204eb0f4", params: [{"name":"launchId","type":"uint256","indexed":true},{"name":"creator","type":"address","indexed":true},{"name":"tokens","type":"uint256","indexed":false},{"name":"members","type":"uint256[10]","indexed":false},{"name":"paid","type":"uint256","indexed":false}] },
14
14
  { name: "Graduated", signature: "Graduated(uint256,uint256,uint256,uint256,uint256)", topic: "0x0ba53bc3beab16da02bf51a54e938fd7c98b7838adc8b1368fc596f9cc85ec5b", params: [{"name":"launchId","type":"uint256","indexed":true},{"name":"windowPriceX64","type":"uint256","indexed":false},{"name":"priceX64","type":"uint256","indexed":false},{"name":"windowRaised","type":"uint256","indexed":false},{"name":"windowTokens","type":"uint256","indexed":false}] },
@@ -97,6 +97,7 @@ export const EVM_ERRORS = [
97
97
  { chain: "evm", name: "PresetDisabled", message: "PresetDisabled", code: null, selector: "0x5518d9cd", signature: "PresetDisabled()" },
98
98
  { chain: "evm", name: "PresetIdNotNext", message: "PresetIdNotNext", code: null, selector: "0x9b5a5243", signature: "PresetIdNotNext()" },
99
99
  { chain: "evm", name: "PresetInvalid", message: "PresetInvalid", code: null, selector: "0x46f63096", signature: "PresetInvalid()" },
100
+ { chain: "evm", name: "PriceOrder", message: "PriceOrder", code: null, selector: "0x6b2c148b", signature: "PriceOrder()" },
100
101
  { chain: "evm", name: "QuoteDisabled", message: "QuoteDisabled", code: null, selector: "0x31ccdc5d", signature: "QuoteDisabled()" },
101
102
  { chain: "evm", name: "QuoteListed", message: "QuoteListed", code: null, selector: "0xe6faf0c2", signature: "QuoteListed()" },
102
103
  { chain: "evm", name: "QuoteNotListed", message: "QuoteNotListed", code: null, selector: "0x06ff137a", signature: "QuoteNotListed()" },
@@ -111,6 +112,7 @@ export const EVM_ERRORS = [
111
112
  { chain: "evm", name: "SafeERC20FailedOperation", message: "SafeERC20FailedOperation", code: null, selector: "0x5274afe7", signature: "SafeERC20FailedOperation(address)" },
112
113
  { chain: "evm", name: "SellTooLarge", message: "SellTooLarge", code: null, selector: "0x8e4d208f", signature: "SellTooLarge()" },
113
114
  { chain: "evm", name: "SlippageExceeded", message: "SlippageExceeded", code: null, selector: "0x8199f5f3", signature: "SlippageExceeded()" },
115
+ { chain: "evm", name: "SqrtRange", message: "SqrtRange", code: null, selector: "0x1e523888", signature: "SqrtRange()" },
114
116
  { chain: "evm", name: "StringsInsufficientHexLength", message: "StringsInsufficientHexLength", code: null, selector: "0xe22e27eb", signature: "StringsInsufficientHexLength(uint256,uint256)" },
115
117
  { chain: "evm", name: "SwapDataNotEmpty", message: "SwapDataNotEmpty", code: null, selector: "0x8821f518", signature: "SwapDataNotEmpty()" },
116
118
  { chain: "evm", name: "SwapFailed", message: "SwapFailed", code: null, selector: "0xff9fa595", signature: "SwapFailed(bytes)" },
@@ -126,5 +128,8 @@ export const EVM_ERRORS = [
126
128
  { chain: "evm", name: "UnknownLaunch", message: "UnknownLaunch", code: null, selector: "0xf6806bf8", signature: "UnknownLaunch()" },
127
129
  { chain: "evm", name: "UUPSUnauthorizedCallContext", message: "UUPSUnauthorizedCallContext", code: null, selector: "0xe07c8dba", signature: "UUPSUnauthorizedCallContext()" },
128
130
  { chain: "evm", name: "UUPSUnsupportedProxiableUUID", message: "UUPSUnsupportedProxiableUUID", code: null, selector: "0xaa1d49a4", signature: "UUPSUnsupportedProxiableUUID(bytes32)" },
131
+ { chain: "evm", name: "VaultShareOutOfRange", message: "VaultShareOutOfRange", code: null, selector: "0xdb8df2d8", signature: "VaultShareOutOfRange()" },
132
+ { chain: "evm", name: "Zero", message: "Zero", code: null, selector: "0xf4560403", signature: "Zero()" },
129
133
  { chain: "evm", name: "ZeroAddress", message: "ZeroAddress", code: null, selector: "0xd92e233d", signature: "ZeroAddress()" },
134
+ { chain: "evm", name: "ZeroLiquidity", message: "ZeroLiquidity", code: null, selector: "0x10074548", signature: "ZeroLiquidity()" },
130
135
  ];
@@ -2,7 +2,7 @@
2
2
 
3
3
  export const SOLANA_EVENT_SCHEMAS = [
4
4
  { name: "LaunchCreated", discriminator: "3b26bee621225914", source: "v1", fields: [["launch","pubkey"],["mint","pubkey"],["quoteMint","pubkey"],["creator","pubkey"],["id","u64"],["presetId","u8"],["presetVersion","u32"],["presetHash","bytes:32"],["p0X64","u128"],["raise","u64"],["windowTokens","u64"],["creatorBuyTokens","u64"],["createFee","u64"],["name","bytes:32"],["symbol","bytes:10"],["slot","u64"],["ts","i64"],["listed","bool"],["quoteUsdCentsX64","u128"],["nativeCreateFee","u64"]] },
5
- { name: "Graduated", discriminator: "33f142328cf59cc0", source: "v1", fields: [["launch","pubkey"],["priceX64","u128"],["windowRaised","u64"],["windowTokens","u64"],["slot","u64"],["ts","i64"]] },
5
+ { name: "Graduated", discriminator: "33f142328cf59cc0", source: "v1", fields: [["launch","pubkey"],["windowPriceX64","u128"],["windowRaised","u64"],["windowTokens","u64"],["slot","u64"],["ts","i64"],["priceX64","u128"]] },
6
6
  { name: "PotsSwept", discriminator: "33480c25b092b903", source: "v1", fields: [["launch","pubkey"],["amount","u64"],["reason","u8"]] },
7
7
  { name: "Claimed", discriminator: "d9c07b486c96f821", source: "v1", fields: [["wallet","pubkey"],["sender","pubkey"],["launch","pubkey"],["quoteMint","pubkey"],["types","u8"],["creator","u64"],["creatorRef","u64"],["teamSlot","u64"],["traderRef","u64"],["extra","u64"],["amount","u64"],["teamBuy","u64?"],["shareBought","u64?"],["typesHi","u8?"]] },
8
8
  { name: "TeamShareBought", discriminator: "40e04bbcf76ac766", source: "v1", fields: [["launch","pubkey"],["member","pubkey"],["place","u8"],["spent","u64"],["refund","u64"],["tokens","u64"],["shareLeft","u64"],["boughtOwed","u64"],["day","u64"],["firstToday","bool"],["ts","i64"]] },
@@ -72,6 +72,20 @@ export function createEvmClient(opts )
72
72
  throw decodeEvmProgramError(e) ?? new FloorError("Transport", `eth_call to ${c.to} failed`, { source: "sdk", cause: e });
73
73
  }
74
74
  };
75
+
76
+ const approvals = async (token , owner , amount ) => {
77
+ let have = null;
78
+ try {
79
+ const pad = (a ) => a.toLowerCase().replace(/^0x/, "").padStart(64, "0");
80
+ const out = await transport.rpc.call({ to: token, data: `0xdd62ed3e${pad(owner)}${pad(floorAmm)}` } );
81
+ if (typeof out === "string" && /^0x[0-9a-fA-F]{64}$/.test(out)) have = BigInt(out);
82
+ } catch {
83
+ have = null;
84
+ }
85
+ if (have !== null && have >= amount) return [];
86
+ if (have !== null && have > 0n) return [approveCall(token, floorAmm, 0n), approveCall(token, floorAmm, amount)];
87
+ return [approveCall(token, floorAmm, amount)];
88
+ };
75
89
  const tx = (calls ) => ({ family: "evm", chainId, calls });
76
90
  const launchIdOf = (launch ) => {
77
91
  if (typeof launch !== "bigint" || launch <= 0n) throw bad("launch: an EVM launch is its launchId, a bigint > 0");
@@ -159,14 +173,14 @@ export function createEvmClient(opts )
159
173
  const launchId = launchIdOf(p.launch);
160
174
  const { quote } = await launchState(launchId);
161
175
  const buy = buyCall({ floorAmm, quote, launchId, amountIn: p.amountIn, minTokensOut: p.minOut, to: p.recipient ?? p.trader, ...(p.deadline !== undefined ? { deadline: p.deadline } : {}) });
162
- return tx(quote.toLowerCase() === NATIVE_QUOTE ? [buy] : [approveCall(quote, floorAmm, p.amountIn), buy]);
176
+ return tx(quote.toLowerCase() === NATIVE_QUOTE ? [buy] : [...(await approvals(quote, p.trader, p.amountIn)), buy]);
163
177
  }),
164
178
 
165
179
  buildSell: (p) => guard(async () => {
166
180
  const launchId = launchIdOf(p.launch);
167
181
  const sell = sellCall({ floorAmm, launchId, tokensIn: p.tokensIn, minQuoteOut: p.minOut, to: p.recipient ?? p.trader, ...(p.deadline !== undefined ? { deadline: p.deadline } : {}) });
168
182
  const { token } = await launchState(launchId);
169
- return tx([approveCall(token, floorAmm, p.tokensIn), sell]);
183
+ return tx([...(await approvals(token, p.trader, p.tokensIn)), sell]);
170
184
  }),
171
185
 
172
186
  claim: (p) => guard(async () => tx([claimV2Call({ floorAmm, wallet: p.wallet, types: p.types, quotes: [p.quote], launchIds: p.launches.map(launchIdOf) })])),
@@ -8,7 +8,7 @@ import { LEG_BACKING, LEG_FLOOR, LEG_HOLDER, LEG_PLATFORM, LEG_TEAM } from "../.
8
8
  import { priceImpactV2, quoteSellImpactV2 } from "../../math/v2/receipt.js";
9
9
  import { sCirc } from "../../math/v2/supply.js";
10
10
  import { CLAIM_SHARE_BOUGHT, CLAIM_TEAM_BUY, CLAIM_TRADER_REF } from "../../solana/floor/instructions.js";
11
- import { FLOOR_AMM_PROGRAM_ID, configPda, launchPda, refOwedPda, refOwedVault, teamSlotPda, traderRefEscrow, traderRefPda } from "../../solana/floor/program.js";
11
+ import { FLOOR_AMM_PROGRAM_ID, configPda, launchPda, refOwedPda, refOwedVault, teamSlotPda, traderLinkPda, traderRefEscrow, traderRefPda } from "../../solana/floor/program.js";
12
12
  import { MAX_COMPUTE_UNIT_LIMIT, computeUnitLimitInstruction } from "../../solana/instruction.js";
13
13
 
14
14
  import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, WSOL_MINT, associatedTokenAddress } from "../../solana/pda.js";
@@ -98,14 +98,23 @@ export function createSolanaClient(opts )
98
98
  return { address, l };
99
99
  }
100
100
 
101
- async function tradeAccounts(address , l , trader , baseOwner , quoteOwner ) {
101
+ async function quoteIsLaunchOf(l ) {
102
+ if (l.quoteTokenProgram !== TOKEN_2022_PROGRAM_ID) return false;
103
+ const a = await get(launchPda(l.quoteMint, pid)[0]);
104
+ return a !== null && a.owner === pid;
105
+ }
106
+
107
+ async function tradeAccounts(address , l , trader , baseOwner , quoteOwner , isBuy ) {
102
108
  const ref = traderRefPda(trader, l.quoteMint, pid)[0];
103
- const hasRef = (await get(ref)) !== null;
109
+ const linked = (await get(traderLinkPda(trader, pid)[0])) !== null;
110
+ const hasRef = linked || (await get(ref)) !== null;
111
+ const out = isBuy ? baseOwner : quoteOwner;
104
112
  return {
105
113
  programId: pid, hookProgramId: hid, trader, launch: address, baseMint: l.baseMint, quoteMint: l.quoteMint, tokenVault: l.tokenVault, quoteVault: l.quoteVault,
106
114
  traderBase: associatedTokenAddress(baseOwner, l.baseMint, TOKEN_2022_PROGRAM_ID), traderQuote: associatedTokenAddress(quoteOwner, l.quoteMint, l.quoteTokenProgram),
107
115
  quoteTokenProgram: l.quoteTokenProgram, traderRef: hasRef ? ref : null, escrow: hasRef ? traderRefEscrow(ref, l.quoteMint, l.quoteTokenProgram) : null,
108
- baseOwner, quoteOwner,
116
+ baseOwner, quoteOwner, quoteIsLaunch: await quoteIsLaunchOf(l),
117
+ ...(linked ? { user: trader, recipient: out !== trader ? out : null } : {}),
109
118
  };
110
119
  }
111
120
 
@@ -187,7 +196,7 @@ export function createSolanaClient(opts )
187
196
  if (p.amountIn <= 0n) throw bad("amountIn must be > 0");
188
197
  const { address, l } = await launchOf(p.launch);
189
198
  const owner = p.recipient ?? p.trader;
190
- const a = await tradeAccounts(address, l, p.trader, owner, p.trader);
199
+ const a = await tradeAccounts(address, l, p.trader, owner, p.trader, true);
191
200
 
192
201
  const hasPosition = owner !== p.trader || (await get(holderPositionPda(address, owner, hid)[0])) !== null;
193
202
  const wsol = await wsolLegs(l, p.trader, p.trader);
@@ -205,7 +214,7 @@ export function createSolanaClient(opts )
205
214
  if (p.tokensIn <= 0n) throw bad("tokensIn must be > 0");
206
215
  const { address, l } = await launchOf(p.launch);
207
216
  const to = p.recipient ?? p.trader;
208
- const a = await tradeAccounts(address, l, p.trader, p.trader, to);
217
+ const a = await tradeAccounts(address, l, p.trader, p.trader, to, false);
209
218
  const wsol = await wsolLegs(l, to, p.trader);
210
219
  const instructions = [
211
220
  computeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT),
@@ -218,28 +227,36 @@ export function createSolanaClient(opts )
218
227
 
219
228
  claim: (p ) => guard(async () => {
220
229
  const tok = (p.types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
221
- const launches = [];
222
230
  let qtp = null;
223
- for (const mint of p.launches) {
231
+ let qIsLaunch = false;
232
+
233
+ const read = await Promise.all(p.launches.map(async (mint) => {
224
234
  const { address, l } = await launchOf(mint);
225
235
  if (l.quoteMint !== p.quote) throw bad(`launch ${mint} trades in ${l.quoteMint}, not ${p.quote}`);
226
- qtp = l.quoteTokenProgram;
227
236
  const slot = teamSlotPda(address, pid)[0];
228
- launches.push({
229
- launch: address, quoteVault: l.quoteVault, teamSlot: (await get(slot)) !== null ? slot : null, baseMint: l.baseMint,
230
- ...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
231
- });
237
+ const [isLaunch, slotAcc] = await Promise.all([quoteIsLaunchOf(l), get(slot)]);
238
+ return { mint, address, l, slot, isLaunch, slotAcc };
239
+ }));
240
+ const launches = read.map(({ address, l, slot, slotAcc }) => ({
241
+ launch: address, quoteVault: l.quoteVault, teamSlot: slotAcc !== null ? slot : null, baseMint: l.baseMint,
242
+ ...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
243
+ }));
244
+ const last = read.at(-1);
245
+ if (last !== undefined) {
246
+ qtp = last.l.quoteTokenProgram;
247
+ qIsLaunch = last.isLaunch;
232
248
  }
233
249
  if (qtp === null) {
234
250
  const m = await get(p.quote);
235
251
  if (m === null) throw new FloorError("BadAccount", `no quote mint ${p.quote}`, { source: "sdk" });
236
252
  qtp = m.owner;
253
+ qIsLaunch = await quoteIsLaunchOf({ quoteMint: p.quote, quoteTokenProgram: qtp } );
237
254
  }
238
255
  const ro = (p.types & CLAIM_TRADER_REF) !== 0 ? refOwedPda(p.wallet, p.quote, pid)[0] : null;
239
256
  const claim = claimInstructionV2({
240
257
  ...ids, sender: p.wallet, wallet: p.wallet, quoteMint: p.quote, quoteTokenProgram: qtp, destination: associatedTokenAddress(p.wallet, p.quote, qtp),
241
258
  config: configPda(pid)[0], refOwed: ro, refOwedVault: ro ? refOwedVault(ro, p.quote, qtp) : null, types: p.types, launches,
242
- unwrap: p.quote === WSOL_MINT && qtp === TOKEN_PROGRAM_ID,
259
+ unwrap: p.quote === WSOL_MINT && qtp === TOKEN_PROGRAM_ID, quoteIsLaunch: qIsLaunch,
243
260
  });
244
261
  return { family: "solana", instructions: [computeUnitLimitInstruction(CLAIM_COMPUTE_UNIT_LIMIT_V2), claim] };
245
262
  }),