@floorlaunchpad/sdk 0.3.2 → 0.4.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +14 -0
  3. package/dist/abi/evm.gen.js +1 -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 +19 -7
  7. package/dist/config/generated.js +26864 -402
  8. package/dist/config/registry.gen.js +33 -2
  9. package/dist/evm/chains.js +9 -1
  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/indexer/bodies.js +91 -17
  14. package/dist/indexer/client.js +34 -14
  15. package/dist/indexer/contract.js +132 -28
  16. package/dist/indexer/partners.js +3 -2
  17. package/dist/indexer/paths.js +61 -29
  18. package/dist/indexer/read.js +27 -15
  19. package/dist/indexer/search.js +130 -0
  20. package/dist/indexer/stack-edge.js +35 -0
  21. package/dist/indexer/stream.js +70 -23
  22. package/dist/math/v2/split.js +11 -3
  23. package/dist/solana/floor/events.js +1 -1
  24. package/dist/solana/floor/genesis.js +9 -3
  25. package/dist/solana/floor/instructions.js +14 -5
  26. package/dist/solana/floor/registry.js +4 -0
  27. package/dist/v2/solana.js +17 -2
  28. package/dist/v2/tx/solana.js +1 -1
  29. package/docs/bot.md +36 -1
  30. package/docs/cursor-pages.md +56 -0
  31. package/docs/floor-line.md +9 -4
  32. package/examples/floor-line.html +6 -6
  33. package/package.json +1 -1
  34. package/src/abi/evm.gen.ts +1 -1
  35. package/src/abi/solana.gen.ts +1 -1
  36. package/src/client/evm/index.ts +16 -2
  37. package/src/client/solana/index.ts +19 -7
  38. package/src/client/types.ts +1 -1
  39. package/src/config/generated.ts +26864 -402
  40. package/src/config/index.ts +9 -2
  41. package/src/config/registry.gen.ts +33 -2
  42. package/src/events/types.gen.ts +2 -1
  43. package/src/evm/chains.ts +9 -1
  44. package/src/evm/floor/abi.gen.ts +1 -1
  45. package/src/evm/floor/events.ts +11 -1
  46. package/src/evm/floor/legacy-events.ts +27 -0
  47. package/src/indexer/bodies.ts +99 -17
  48. package/src/indexer/client.ts +52 -30
  49. package/src/indexer/contract.ts +151 -29
  50. package/src/indexer/partners.ts +3 -2
  51. package/src/indexer/paths.ts +84 -29
  52. package/src/indexer/read.ts +33 -17
  53. package/src/indexer/search.ts +138 -0
  54. package/src/indexer/stack-edge.ts +46 -0
  55. package/src/indexer/stream.ts +78 -24
  56. package/src/math/v2/split.ts +11 -3
  57. package/src/solana/floor/events.ts +1 -1
  58. package/src/solana/floor/genesis.ts +8 -2
  59. package/src/solana/floor/instructions.ts +13 -5
  60. package/src/solana/floor/registry.ts +4 -0
  61. package/src/v2/solana.ts +20 -3
  62. package/src/v2/tx/solana.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,72 @@
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.0
6
+
7
+ Removed:
8
+
9
+ - `LAUNCHES_ALL` (the body of `floor-amm/launches` with no query key). No request answers every launch any more: a bare
10
+ `floor-amm/launches` is one page, decoded by `LAUNCHES`.
11
+
12
+ Changed:
13
+
14
+ - `INDEXER_CONTRACT.launches`: the default `limit` is `LAUNCHES_PAGE_DEFAULT` (100, was 1000); the page kind is the new
15
+ `keyset` (`Pagination` gains `{ kind: "keyset", limit, cursor: "cursor", next: "next" }`); the keys gain `preset` and
16
+ `cursor` (`cursor` not with `offset` or `ids`).
17
+ - `LAUNCHES` (the list body) gains `cursors` (the cursor after each row), `keys` (each row's ranked key as a decimal
18
+ string, null in the unread tail) and `next` (the last cursor while rows remain, else null). `cursors` and `keys` are []
19
+ with `ids` or `offset`; an indexer without them decodes with `cursors` / `keys` [] and `next` absent.
20
+ - A `string` query key's `max` bounds the raw length as sent; a `list` key may bound each item (`item`); `required` is
21
+ refused by the table on `search` only.
22
+ - `drain("launches")` follows `next` as `cursor` (by `total` with `offset`).
23
+
24
+ - The six wallet routes page on request: `positions`, `walletLocks`, `claimHistory`, `people` and `roles` take `limit`
25
+ (default `WALLET_PAGE_DEFAULT` 100, at most `WALLET_PAGE_MAX` 500) and `cursor` (opaque, at most `WALLET_CURSOR_MAX`
26
+ characters) and answer `next`; `inbox` takes `before` (`""` the newest; default `INBOX_PAGE_DEFAULT` 100, at most
27
+ `INBOX_PAGE_MAX` 500) and answers `next`. With neither key each answers every row, as before. Their decoders
28
+ (`POSITIONS`, `WALLET_LOCKS`, `CLAIM_HISTORY`, `PEOPLE`, `ROLES`, `INBOX`) gain an optional `next`; the readers
29
+ (`readPositions`, `readWalletLocks`, `readClaimHistory`, `readPeople`, `readRoles`, `readInbox`) take the page keys.
30
+ - Four more routes page, with a page of 100 rows when no key is sent: `floorRouted` (`limit` up to `LAUNCHES_PAGE_MAX`
31
+ 1,000, `cursor` the last launch id, create order; `pending` stays the whole per-quote sum on every page), `devBuys`
32
+ (`limit` up to 500, `before` a block or a row id, newest first), `claimView` (`limit` up to `WALLET_PAGE_MAX` 500,
33
+ `cursor` the last row key: `l:<launch>`, `r:<account>`, `p:<traderRef>` or `o:<quote>`; `quotes` and `totals` stay
34
+ whole) and `handlePlaces` (`limit` up to 500, `cursor` `<launch>:<place>`). Each body (`FLOOR_ROUTED`, `DEV_BUYS`,
35
+ `CLAIM_VIEW`, `HANDLE_PLACES`) gains an optional `next`, null on the last page; `indexerPath`, `routePath` and the readers
36
+ (`readDevBuys`, `readClaimView`, `readHandlePlaces`) take the page keys, and `DRAIN_NAMES` gains the four.
37
+ - **Breaking:** a `DEV_BUY` row carries a required `id` (`<block>:<txnIndex>:<eventIndex>`, the `before` cursor). This
38
+ build's decoder refuses a dev-buys body from an indexer older than it, which sends rows without `id`.
39
+ - A candle (`readCandles`, `floor-amm/candles` and the candle bundle) gains `floorX64`: the floor at the bucket's close, a
40
+ Q64.64 price as a launch's own `floorX64`. It is absent from an indexer older than this build and null where the bucket
41
+ has none.
42
+ - `DEX_PAIR`: the pair gains `dexKey`, `createdAtTxnId` (optional) and `creator`; the body gains an optional `launch`
43
+ (`{ id, token }`), so a pair resolves to its launch in one read.
44
+ - **Breaking:** `roles.traderRefOf[].tier` is 1-based (1..3), as `creatorRefOf`'s; it was 0-based. A client that
45
+ added 1 to show a tier must stop.
46
+
47
+ Added:
48
+
49
+ - Indexer: the route `GET /floor-amm/search?q=` (also under `/floor-amm/v2/`; `INDEXER_CONTRACT.search`,
50
+ `indexerPath.search`, reader `search`, `readLaunchSearch`, decoder `LAUNCH_SEARCH`, type `LaunchSearch`): launches whose
51
+ symbol, name or token match, best first, each row with its `tier` (0..4), keyset pages by `next`; keys `q`, `limit`
52
+ (default `SEARCH_PAGE_DEFAULT` 12, at most `SEARCH_PAGE_MAX` 100), `cursor`, `rankable`, `graduated`, `quote`, `preset`.
53
+ - `src/indexer/search.ts`: `searchFold`, `searchNeedle`, `searchNeedles` (a query with a leading `$` has two readings,
54
+ without and with it; its tier is the better), `searchTier`, `searchTierFolded`, `searchServed`, `searchServedTier`,
55
+ `SEARCH_PARITY_CORPUS`, `SEARCH_Q_MAX`, `SEARCH_PAGE_DEFAULT`, `SEARCH_PAGE_MAX`, `ADDRESS_PREFIX_MIN`,
56
+ `SEARCH_SUBSTRING_MIN`; `paths.ts`: `LAUNCHES_PAGE_DEFAULT`, `LAUNCH_CURSOR_MAX`, `PRESET_FILTER_MAX`, the `preset` and
57
+ `cursor` keys of `LaunchesQuery`, `LaunchSearchQuery`.
58
+ - `cursorPage` / `CursorPage` (one `{ rows, next }` off any page body), `pageAsked`, `pageLimit`, the type `WalletPage`.
59
+ - 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`.
60
+ - 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.
61
+ - 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).
62
+ - Chains: `elysium` (Elysium, chain 99901, native HYPE; Kinetiq's Arbitrum Orbit L2 on HyperEVM) in the chain registry,
63
+ `EVM_CHAINS` and the config rows, marked `v2DayOne: false` (an added chain, not v2 day one): `v2DayOneChains()` still
64
+ 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.
65
+ - 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`).
66
+
67
+ Fixed:
68
+
69
+ - 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).
70
+
5
71
  ## 0.3.2
6
72
 
7
73
  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
 
@@ -45,6 +46,14 @@ $FLOOR fee; the other three start at graduation. The rates are the launch's own,
45
46
  the quote rather than from a table. Marketcap Milestones are not fees: they sit inside the price, are paid only by buys on
46
47
  the way up and never appear in `fees`.
47
48
 
49
+ **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`.
50
+
51
+ **Governance actions on TON.** `src/ton/governance.ts` decodes the body of every governance message on TON (the
52
+ timelock's `schedule` / `execute` / `cancel`, and every authority, timelock and upgrade op of the factory and a launch) into
53
+ the op, its target, every field (amounts with their decimals, code hashes, a scheduled action decoded too) and plain text
54
+ lines, so a multisig shows exactly what is signed before anyone signs. It refuses an unknown op, a truncated body, or a bit
55
+ or a reference left over, rather than show part of a body. `buildTonGovBody` builds the same bodies; neither signs nor sends.
56
+
48
57
  **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
58
 
50
59
  ```ts
@@ -60,6 +69,11 @@ const page = await readTrades(get, launch.id, { limit: 50 });
60
69
  const older = page.next === null ? null : await readTrades(get, launch.id, { limit: 50, before: page.next });
61
70
  ```
62
71
 
72
+ Lists come in pages. `readLaunches` answers 100 launches a page, and no request answers them all. `readLaunchSearch`
73
+ finds launches by symbol, name or token. The wallet lists, such as `readPositions` and `readClaimHistory`, page when you
74
+ ask with `limit` or `cursor`. Each page carries `next`, and [docs/cursor-pages.md](docs/cursor-pages.md) says which key
75
+ takes it back on each route. `readCandles` returns each candle with `floorX64`, the floor at that candle's close.
76
+
63
77
  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
78
 
65
79
  **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}] },
@@ -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),
@@ -220,10 +229,12 @@ export function createSolanaClient(opts )
220
229
  const tok = (p.types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
221
230
  const launches = [];
222
231
  let qtp = null;
232
+ let qIsLaunch = false;
223
233
  for (const mint of p.launches) {
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
236
  qtp = l.quoteTokenProgram;
237
+ qIsLaunch = await quoteIsLaunchOf(l);
227
238
  const slot = teamSlotPda(address, pid)[0];
228
239
  launches.push({
229
240
  launch: address, quoteVault: l.quoteVault, teamSlot: (await get(slot)) !== null ? slot : null, baseMint: l.baseMint,
@@ -234,12 +245,13 @@ export function createSolanaClient(opts )
234
245
  const m = await get(p.quote);
235
246
  if (m === null) throw new FloorError("BadAccount", `no quote mint ${p.quote}`, { source: "sdk" });
236
247
  qtp = m.owner;
248
+ qIsLaunch = await quoteIsLaunchOf({ quoteMint: p.quote, quoteTokenProgram: qtp } );
237
249
  }
238
250
  const ro = (p.types & CLAIM_TRADER_REF) !== 0 ? refOwedPda(p.wallet, p.quote, pid)[0] : null;
239
251
  const claim = claimInstructionV2({
240
252
  ...ids, sender: p.wallet, wallet: p.wallet, quoteMint: p.quote, quoteTokenProgram: qtp, destination: associatedTokenAddress(p.wallet, p.quote, qtp),
241
253
  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,
254
+ unwrap: p.quote === WSOL_MINT && qtp === TOKEN_PROGRAM_ID, quoteIsLaunch: qIsLaunch,
243
255
  });
244
256
  return { family: "solana", instructions: [computeUnitLimitInstruction(CLAIM_COMPUTE_UNIT_LIMIT_V2), claim] };
245
257
  }),