@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.
- package/CHANGELOG.md +94 -0
- package/README.md +16 -0
- package/dist/abi/evm.gen.js +6 -1
- package/dist/abi/solana.gen.js +1 -1
- package/dist/client/evm/index.js +16 -2
- package/dist/client/solana/index.js +31 -14
- package/dist/config/generated.js +26864 -402
- package/dist/config/registry.gen.js +33 -2
- package/dist/evm/chains.js +85 -16
- package/dist/evm/floor/abi.gen.js +1 -1
- package/dist/evm/floor/events.js +9 -1
- package/dist/evm/floor/legacy-events.js +25 -0
- package/dist/evm/router.js +25 -1
- package/dist/evm/squid.js +9 -9
- package/dist/evm/zap.js +148 -35
- package/dist/indexer/bodies.js +96 -17
- package/dist/indexer/client.js +36 -14
- package/dist/indexer/contract.js +178 -28
- package/dist/indexer/partners.js +3 -2
- package/dist/indexer/paths.js +87 -29
- package/dist/indexer/read.js +30 -15
- package/dist/indexer/search.js +130 -0
- package/dist/indexer/stack-edge.js +35 -0
- package/dist/indexer/stream.js +70 -23
- package/dist/math/v2/split.js +11 -3
- package/dist/solana/floor/events.js +1 -1
- package/dist/solana/floor/genesis.js +9 -3
- package/dist/solana/floor/instructions.js +14 -5
- package/dist/solana/floor/registry.js +4 -0
- package/dist/v2/devbuy.js +6 -4
- package/dist/v2/presetRowEvm.js +21 -2
- package/dist/v2/solana.js +17 -2
- package/dist/v2/tx/solana.js +1 -1
- package/docs/aggregator.md +22 -0
- package/docs/bot.md +44 -1
- package/docs/cursor-pages.md +58 -0
- package/docs/floor-line.md +9 -4
- package/docs/frontend.md +2 -0
- package/docs/wallet.md +2 -0
- package/examples/floor-line.html +6 -6
- package/package.json +1 -1
- package/src/abi/evm.gen.ts +6 -1
- package/src/abi/solana.gen.ts +1 -1
- package/src/client/evm/index.ts +16 -2
- package/src/client/solana/index.ts +31 -14
- package/src/client/types.ts +1 -1
- package/src/config/generated.ts +26864 -402
- package/src/config/index.ts +9 -2
- package/src/config/registry.gen.ts +33 -2
- package/src/events/types.gen.ts +2 -1
- package/src/evm/chains.ts +94 -15
- package/src/evm/floor/abi.gen.ts +1 -1
- package/src/evm/floor/events.ts +11 -1
- package/src/evm/floor/legacy-events.ts +27 -0
- package/src/evm/router.ts +26 -1
- package/src/evm/squid.ts +9 -9
- package/src/evm/zap.ts +185 -36
- package/src/indexer/bodies.ts +106 -17
- package/src/indexer/client.ts +56 -30
- package/src/indexer/contract.ts +197 -29
- package/src/indexer/partners.ts +3 -2
- package/src/indexer/paths.ts +131 -29
- package/src/indexer/read.ts +36 -17
- package/src/indexer/search.ts +138 -0
- package/src/indexer/stack-edge.ts +46 -0
- package/src/indexer/stream.ts +78 -24
- package/src/math/v2/split.ts +11 -3
- package/src/solana/floor/events.ts +1 -1
- package/src/solana/floor/genesis.ts +8 -2
- package/src/solana/floor/instructions.ts +13 -5
- package/src/solana/floor/registry.ts +4 -0
- package/src/v2/devbuy.ts +6 -4
- package/src/v2/presetRowEvm.ts +21 -2
- package/src/v2/solana.ts +20 -3
- package/src/v2/tx/solana.ts +1 -1
package/docs/aggregator.md
CHANGED
|
@@ -51,11 +51,33 @@ const call = evmRouteCallV2(q, { router, to: recipient, deadline });
|
|
|
51
51
|
// { to, data, ... }: send it from the trader's wallet
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
## Pay with another coin (EVM zap)
|
|
55
|
+
|
|
56
|
+
A buyer who holds the native coin, or an ERC-20 that is not the launch's quote, buys through a FloorZap, which swaps into the quote and buys in one transaction.
|
|
57
|
+
|
|
58
|
+
- Addresses: `FLOOR_ZAP_ADDRESSES` (`@floorlaunchpad/sdk/evm/chains`) holds the deployed zap per chain and router slot, 15 instances on 8 chains. Each `EVM_CHAINS` zap row carries its own `zap`, `null` where that slot is not deployed. Keep no copy of your own.
|
|
59
|
+
- Swap calldata: `zapSwapData` (`@floorlaunchpad/sdk/evm/zap`) builds the zap's `swapData`. The input is the native coin (the default) or an ERC-20 (`input: "token"`). The output is the launch's ERC-20 quote (the default) or, for a launch quoted in the native coin, the native coin (`output: "native"`).
|
|
60
|
+
- A Universal Router fork row passes that row's `urFork` (`"uniswap"`, `"aerodrome"`, `"pancake"` or `"ramses"`). Uniswap v4 is one pool given as `route.v4`. A native-input Universal Router swap ends with a `SWEEP`, so anything the swap did not spend goes back to the zap, which refunds it.
|
|
61
|
+
- Bridged buys: `buyHookNative` (in `src/evm/squid.ts`) builds the destination-chain hook calls. Pass the launch's `quote`. For an ERC-20 quote the hook adds a third call that passes the quote refund on to the user. Absent or address(0), it is the two calls of 0.4.0.
|
|
62
|
+
|
|
63
|
+
## FloorRouter addresses (EVM)
|
|
64
|
+
|
|
65
|
+
`evmRouteCallV2` takes the FloorRouter's address as `router`. The SDK books one per chain and zap slot: `FLOOR_ROUTER_ADDRESSES` and each zap row's `floorRouter` (`@floorlaunchpad/sdk/evm/chains`), the same address for a slot on every chain that has it. They are derived ahead of the routers' deploy, so an address is usable only once it has code on that chain. Before then a call to it still succeeds and buys nothing, and a native-in buy's coin goes to the empty address and is lost. Check it first (`getCode` answering "0x" or `undefined` is no code):
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { FLOOR_ROUTER_ADDRESSES } from "@floorlaunchpad/sdk/evm/chains";
|
|
69
|
+
import { assertFloorRouterLive } from "@floorlaunchpad/sdk/evm/router";
|
|
70
|
+
|
|
71
|
+
const router = await assertFloorRouterLive({ getCode: (a) => rpc.getCode(a) }, { chain: "base", slot: "uniswap-ur" });
|
|
72
|
+
// throws while the router has no code; otherwise pass `router` to evmRouteCallV2
|
|
73
|
+
```
|
|
74
|
+
|
|
54
75
|
## Things to know
|
|
55
76
|
|
|
56
77
|
- The SDK never sends or signs. It returns instructions or calldata.
|
|
57
78
|
- Fees are added on top of the amount in and come out of the quote you build the call from. Do not subtract them again.
|
|
58
79
|
- Every launch trades from its first block and neither buys nor sells can be paused. A hop that fails does so because of the amount or the slippage bound, not a switch.
|
|
59
80
|
- Amounts are `bigint` in the coin's smallest unit on both chains.
|
|
81
|
+
- A failed EVM call decodes with `decodeEvmProgramError` (`@floorlaunchpad/sdk/errors`), which also knows the five errors the contracts' math libraries revert with: `PriceOrder()`, `ZeroLiquidity()`, `SqrtRange()`, `Zero()` and `VaultShareOutOfRange()`.
|
|
60
82
|
|
|
61
83
|
See also: [README](../README.md), [bot guide](bot.md) for reading launches to build your pool list.
|
package/docs/bot.md
CHANGED
|
@@ -18,7 +18,50 @@ const { launch } = await readLaunch(get, "42");
|
|
|
18
18
|
const page = await readTrades(get, launch.id, { limit: 100 });
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
Pages carry a `next` cursor; pass it as `before`
|
|
21
|
+
Pages carry a `next` cursor; stop when it is `null`. On trades, marks and the inbox pass it back as `before`; on `launches`, `search` and the other wallet routes pass it back as `cursor`. Amounts are `bigint`. A non-200 answer throws an `IndexerError` (`notReady` while the indexer catches up, `unknownLaunch` for an id it does not know). A body of the wrong shape throws a `ShapeError` that names the field.
|
|
22
|
+
|
|
23
|
+
### List and search launches
|
|
24
|
+
|
|
25
|
+
`readLaunches` answers one page, 100 launches by default. No request answers every launch, so walk the pages:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { readLaunches, readLaunchSearch, readCandles } from "@floorlaunchpad/sdk/indexer/read";
|
|
29
|
+
|
|
30
|
+
let cursor: string | undefined;
|
|
31
|
+
do {
|
|
32
|
+
const page = await readLaunches(get, { limit: 100, cursor });
|
|
33
|
+
// page.launches …
|
|
34
|
+
cursor = page.next ?? undefined;
|
|
35
|
+
} while (cursor !== undefined);
|
|
36
|
+
|
|
37
|
+
const hits = await readLaunchSearch(get, { q: "wagmi" }); // best match first, each row with its tier
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
A client made with `createIndexerClient` walks them for you: `for await (const page of ix.drain("launches", {}))`.
|
|
41
|
+
|
|
42
|
+
### Wallet lists
|
|
43
|
+
|
|
44
|
+
Called with neither `limit` nor `cursor`, `readPositions`, `readWalletLocks`, `readClaimHistory`, `readRoles` and
|
|
45
|
+
`readPeople` return the whole list. Pass either one to get pages: a page is 100 rows unless `limit` asks for another
|
|
46
|
+
size, and 500 at most. `readInbox` pages with `before`. Every list is in [cursor-pages.md](cursor-pages.md).
|
|
47
|
+
|
|
48
|
+
### Candles with the floor
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const { candles } = await readCandles(get, { launch: launch.id, interval: "1h" });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Each candle carries `floorX64`, the floor at the bucket's close, in the same Q64.64 units as a launch's `floorX64`. It is
|
|
55
|
+
`null` where a bucket has none, and absent from an indexer older than this build. Use the launch's own `floorX64` for
|
|
56
|
+
that candle then. [floor-line.md](floor-line.md) shows how to draw it.
|
|
57
|
+
|
|
58
|
+
### Many launches in one request
|
|
59
|
+
|
|
60
|
+
`readLaunchLists(get, { quotes, cursors })` returns one `launches` page per quote coin (up to 16) in one answer, each list resumed with its own cursor (`"-"` asks a first page). `readCandlesMany(get, { ids, interval })` returns the newest candles of up to 40 launches at once. Both are in `@floorlaunchpad/sdk/indexer/read`; the limits are in [cursor-pages.md](cursor-pages.md).
|
|
61
|
+
|
|
62
|
+
### Dev buys through a zap or router
|
|
63
|
+
|
|
64
|
+
A buy through a zap or a router has the contract as the trade's `trader`. Pass the person that contract's own event names as `ctx.buyer` to `devBuyFromTrade` (`@floorlaunchpad/sdk/v2/devbuy`), and a creator's or team member's buy through it counts as a dev buy, with that person as `trader`. The trade's recipient alone never names one.
|
|
22
65
|
|
|
23
66
|
## Follow the live stream
|
|
24
67
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Cursor pages
|
|
2
|
+
|
|
3
|
+
Every list route of the FLOOR indexer that pages by cursor follows one contract.
|
|
4
|
+
|
|
5
|
+
## Request
|
|
6
|
+
|
|
7
|
+
`?<cursor key>=<cursor>&limit=<n>`. The cursor key is `cursor` on every route, except where a route already took `before`
|
|
8
|
+
before cursor pages existed (`launches/<id>/trades`, `wallets/<w>/trades`, `launches/<id>/marks`, `wallets/<w>/inbox`).
|
|
9
|
+
`limit` has a per-route maximum (500 at most for a wallet page); the contract table (`INDEXER_CONTRACT`, `routeLimit`)
|
|
10
|
+
holds each route's default and maximum. A `limit` above the maximum is a 400 (`limit must be 1..500`, with the route's
|
|
11
|
+
own bounds), never a silent clamp.
|
|
12
|
+
|
|
13
|
+
The wallet routes `positions`, `locks`, `claims`, `roles` and `referrals/<w>/people` answer a page only when one is asked
|
|
14
|
+
(`limit`, or a non-empty `cursor`). The inbox answers a page when `before` is present, and an empty `before` asks the
|
|
15
|
+
newest page. Asked with none of these, each route answers its whole list in one body.
|
|
16
|
+
|
|
17
|
+
## Defaults
|
|
18
|
+
|
|
19
|
+
| route | reader | cursor key | `limit` default | `limit` maximum |
|
|
20
|
+
|---|---|---|---|---|
|
|
21
|
+
| `launches` | `readLaunches` | `cursor` | `LAUNCHES_PAGE_DEFAULT` (100) | `LAUNCHES_PAGE_MAX` (1,000) |
|
|
22
|
+
| `search?q=` | `readLaunchSearch` | `cursor` | `SEARCH_PAGE_DEFAULT` (12) | `SEARCH_PAGE_MAX` (100) |
|
|
23
|
+
| `wallets/<w>/positions`, `locks`, `claims`, `roles/<w>`, `referrals/<w>/people` | `readPositions`, `readWalletLocks`, `readClaimHistory`, `readRoles`, `readPeople` | `cursor` | `WALLET_PAGE_DEFAULT` (100) | `WALLET_PAGE_MAX` (500) |
|
|
24
|
+
| `wallets/<w>/inbox` | `readInbox` | `before` | `INBOX_PAGE_DEFAULT` (100) | `INBOX_PAGE_MAX` (500) |
|
|
25
|
+
| `launch-lists` (up to 16 quotes) | `readLaunchLists` | `cursors`, one per quote (`"-"` = its first page) | 100 per list | `limit` × quotes ≤ 1,000 rows |
|
|
26
|
+
| `candles/many` (up to 40 launches) | `readCandlesMany` | `before` | 1,000 candles per launch | `limit` × ids ≤ 40,000 candles |
|
|
27
|
+
|
|
28
|
+
No request answers every launch: a bare `launches` is one page of 100. The list body also carries `cursors` (the cursor
|
|
29
|
+
after each row) and `keys` (each row's ranked key); `launches` takes a `preset` filter.
|
|
30
|
+
|
|
31
|
+
## Answer
|
|
32
|
+
|
|
33
|
+
`{ …, <rows>: [...], next: <string> | null }`. `next` is null at the end; passing it back as the cursor returns the
|
|
34
|
+
following page. `cursorPage(body, rowsKey)` reads any decoded page body as `{ rows, next }`; `drain` walks every page.
|
|
35
|
+
|
|
36
|
+
## Cursor
|
|
37
|
+
|
|
38
|
+
One format on every cursored route, except the trades pages' `before` (see below). The indexer alone writes and reads
|
|
39
|
+
it: it is base64url of a small JSON object whose first keys are
|
|
40
|
+
`v` (the version, 1), `r` (the route) and `f` (a hash of the query). The position of the page's last row follows. A
|
|
41
|
+
client treats it as opaque: it passes back the `next` the indexer served, and bounds the length
|
|
42
|
+
(`WALLET_CURSOR_MAX` for a wallet page, `LAUNCH_CURSOR_MAX` for `launches` and `search`).
|
|
43
|
+
|
|
44
|
+
| route | order | `next` positions the page after |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `wallets/<w>/inbox` (`before`), `wallets/<w>/claims` | newest first | the last row (block, txnIndex, eventIndex) |
|
|
47
|
+
| `wallets/<w>/positions`, `wallets/<w>/locks`, `roles/<w>` | launch create order | the last launch (createdBlock, id) |
|
|
48
|
+
| `referrals/<w>/people` | referred wallet ascending | the last wallet |
|
|
49
|
+
| `launches`, `search` | the asked sort | the last row's key and tie (`cursors[i]` per row on the list) |
|
|
50
|
+
|
|
51
|
+
A cursor names its query: one served for another route, another wallet or other filters is a 400 `cursor: not for this
|
|
52
|
+
query`. One that does not decode, or whose fields do not fit the chain, is a 400 `cursor: malformed`. A row id or a bare
|
|
53
|
+
block is not a cursor. A row keeps its own `id` (the inbox's `<block>:<txnIndex>:<eventIndex>`).
|
|
54
|
+
|
|
55
|
+
A page never splits rows that share one position: it ends before them, or takes them all when they alone fill it.
|
|
56
|
+
|
|
57
|
+
The trades pages (`launches/<id>/trades`, `wallets/<w>/trades`, `launches/<id>/marks`) predate this format and keep
|
|
58
|
+
`before` = a block or a trade's `id` (`<block>:<txnIndex>:<eventIndex>`), with `next` the last trade's `id`.
|
package/docs/floor-line.md
CHANGED
|
@@ -21,7 +21,7 @@ snippet on this page. Open it in a browser. It needs no network and no key.
|
|
|
21
21
|
|
|
22
22
|
**Anything more is a bonus.** In rough order of how much it helps:
|
|
23
23
|
|
|
24
|
-
-
|
|
24
|
+
- The Max Loss: how far the price can fall to the floor, `1 − floor ÷ price` as a percentage before fees (`Max Loss 25%`), or `price is 1.33× the floor`.
|
|
25
25
|
- A FLOOR column in token lists and screeners.
|
|
26
26
|
- The FLOOR price in a wallet's holding row, next to the holding's value.
|
|
27
27
|
- An alert when the price comes near the floor.
|
|
@@ -50,7 +50,7 @@ URL is refused). Ask for a key at contact@floor.supply or on X. The reference is
|
|
|
50
50
|
|---|---|---|
|
|
51
51
|
| `GET /launches/{chain}/{token}` | `data.market.floorPriceQuote` | The floor now, whole quote per whole token |
|
|
52
52
|
| | `data.market.floorPriceUsd` | The same in USD at the live rate |
|
|
53
|
-
| | `data.market.priceQuote`, `data.market.
|
|
53
|
+
| | `data.market.priceQuote`, `data.market.maxLossPct` | The price now, and the Max Loss (1 − floor ÷ price, before fees) as a percentage |
|
|
54
54
|
| `GET /launches/{chain}/{token}/trades` | `data[].floorPriceQuote` | The floor after each trade: the history of the line |
|
|
55
55
|
|
|
56
56
|
`null` means there is no floor yet (the launch is still in Bonding) or the figure was not read. Never draw a `null` as 0.
|
|
@@ -116,6 +116,11 @@ per whole token from a Q64.64 value:
|
|
|
116
116
|
const floor = Number((floorX64 * 10n ** 6n * 10n ** 12n) / (1n << 64n)) / 10 ** (quoteDecimals + 12);
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
+
If you draw candles from the FLOOR indexer, you need no second read: every candle of `readCandles(get, { launch, interval })`
|
|
120
|
+
carries `floorX64`, the floor at that bucket's close, in the same Q64.64 units. Draw one floor point per candle. It is
|
|
121
|
+
`null` where a bucket has none and absent from an indexer older than SDK 0.4.0, so fall back to the launch's own
|
|
122
|
+
`floorX64` then.
|
|
123
|
+
|
|
119
124
|
## Draw it
|
|
120
125
|
|
|
121
126
|
**The look.** A solid line, 2 px, FLOOR orange `#FF6A1A`, labelled `FLOOR`, with its value on the price axis in the same
|
|
@@ -193,7 +198,7 @@ previous floor, then a vertical step up to the new floor. The example page does
|
|
|
193
198
|
<div class="stat">
|
|
194
199
|
<span class="label">FLOOR</span>
|
|
195
200
|
<span class="value" style="color:#FF6A1A">$0.0189</span>
|
|
196
|
-
<span class="note">
|
|
201
|
+
<span class="note">Max Loss 25%</span> <!-- bonus -->
|
|
197
202
|
</div>
|
|
198
203
|
```
|
|
199
204
|
|
|
@@ -230,6 +235,6 @@ not a promise about the market price, and the market price can sit far above it.
|
|
|
230
235
|
- [ ] Nothing is drawn before graduation; `null` is never drawn as 0.
|
|
231
236
|
- [ ] The line keeps its history and keeps going after graduation.
|
|
232
237
|
- [ ] Market-cap mode scales the floor by the same supply as the price, or hides it.
|
|
233
|
-
- [ ] Optional:
|
|
238
|
+
- [ ] Optional: the Max Loss, a list column, a wallet row, an alert.
|
|
234
239
|
|
|
235
240
|
Shipped it, or stuck? Tell us at contact@floor.supply. We will check it with you and point FLOOR holders to your page.
|
package/docs/frontend.md
CHANGED
|
@@ -24,6 +24,8 @@ Use the routing functions in [docs/aggregator.md](aggregator.md). For a single l
|
|
|
24
24
|
|
|
25
25
|
- Route modules in `src/route` and `src/v2/route.ts` contain no host names, so a strict content security policy does not trip on them. Anything that talks to a hosted service is in `route-jupiter.ts` and is opt-in.
|
|
26
26
|
- Keep the quote fresh: re-quote when the user changes the amount and just before they sign.
|
|
27
|
+
- A buy paid in another coin goes through the chain's FloorZap: take its address from the zap row's `zap` (`FLOOR_ZAP_ADDRESSES`, `@floorlaunchpad/sdk/evm/chains`) and its swap from `zapSwapData`; [aggregator.md](aggregator.md) has the details.
|
|
28
|
+
- The create page's preset menu on EVM: `readPresetMenuEvmV2` (`@floorlaunchpad/sdk/v2/presetRowEvm`) reads the rows through one Multicall3 `aggregate3` per 100 ids. Pass `{ multicall }` for another Multicall3 address, or `{ multicall: null }` on a chain without one (one call per id). A row that fails throws; the menu never has a gap.
|
|
27
29
|
- Chain choice happens once, at the edge. Past that point the same quote and build calls work on both chains.
|
|
28
30
|
|
|
29
31
|
See also: [README](../README.md), [wallet guide](wallet.md).
|
package/docs/wallet.md
CHANGED
|
@@ -30,6 +30,8 @@ import { decodeErrorV2 } from "@floorlaunchpad/sdk/v2/evm";
|
|
|
30
30
|
const name = decodeErrorV2(revertData); // the custom error's name, or null
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
`decodeEvmProgramError` (`@floorlaunchpad/sdk/errors`) returns the same name with the module and code, and also knows five errors from the contracts' math libraries that the ABI does not list: `PriceOrder()`, `ZeroLiquidity()`, `SqrtRange()`, `Zero()` and `VaultShareOutOfRange()`.
|
|
34
|
+
|
|
33
35
|
Show the name and your own plain wording for it. The SDK gives you the identifier, not a sentence.
|
|
34
36
|
|
|
35
37
|
## Claim
|
package/examples/floor-line.html
CHANGED
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
<div class="stats">
|
|
89
89
|
<div class="stat"><div class="k">Price</div><div class="v" id="sPrice">–</div></div>
|
|
90
90
|
<div class="stat ask"><span class="tag">asked</span><div class="k">FLOOR</div><div class="v" id="sFloor">–</div></div>
|
|
91
|
-
<div class="stat"><span class="tag bonus">bonus</span><div class="k">
|
|
91
|
+
<div class="stat"><span class="tag bonus">bonus</span><div class="k">Max Loss</div><div class="v" id="sMaxLoss">–</div></div>
|
|
92
92
|
<div class="stat"><div class="k">Market cap</div><div class="v" id="sMcap">–</div></div>
|
|
93
93
|
</div>
|
|
94
94
|
<div class="bar">
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
</ol>
|
|
117
117
|
<h3>Bonus</h3>
|
|
118
118
|
<ul>
|
|
119
|
-
<li><code
|
|
119
|
+
<li><code>Max Loss</code> (1 − floor ÷ price, before fees)</li>
|
|
120
120
|
<li>A FLOOR column in lists and screeners</li>
|
|
121
121
|
<li>The FLOOR price in a wallet's holding row</li>
|
|
122
122
|
<li>An alert near the floor</li>
|
|
@@ -149,7 +149,7 @@ const API = "https://floor.supply/api/v1";
|
|
|
149
149
|
const { data: launch } = await (await fetch(`${API}/launches/${chain}/${token}`, H)).json();
|
|
150
150
|
const price = launch.market.priceQuote;
|
|
151
151
|
const floor = launch.market.floorPriceQuote; // null: no floor yet
|
|
152
|
-
const
|
|
152
|
+
const maxLoss = launch.market.maxLossPct; // bonus: 1 − floor / price, in %, before fees
|
|
153
153
|
|
|
154
154
|
// 2. the history of the line: the floor after every trade
|
|
155
155
|
const { data: trades, meta } = await (await fetch(`${API}/launches/${chain}/${token}/trades?limit=100`, H)).json();
|
|
@@ -234,11 +234,11 @@ const floor = floorOf(BigInt(event.sqrtF), quoteDecimals);</script>
|
|
|
234
234
|
<script type="text/plain" id="c-stat" data-label="Token page" data-note="The FLOOR price next to the price. Before graduation: FLOOR with a dash, or leave it out."><div class="stat">
|
|
235
235
|
<span class="label">FLOOR</span>
|
|
236
236
|
<span class="value" style="color:#FF6A1A">${fmt(floor)}</span>
|
|
237
|
-
<span class="note">
|
|
237
|
+
<span class="note">Max Loss ${maxLoss.toFixed(0)}%</span> <!-- bonus -->
|
|
238
238
|
</div></script>
|
|
239
239
|
|
|
240
240
|
<script>
|
|
241
|
-
const DATA = /*DATA*/{"run":"A simulated launch with a USDC quote at $1: 74 buys and 8 sells","quoteDecimals":6,"series":[{"i":0,"price":0.01,"floor":null,"graduated":false,"side":"open"},{"i":1,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":2,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":3,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":4,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":5,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":6,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":7,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":8,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":9,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":10,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":11,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":12,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":13,"price":0.01022274,"floor":0.01,"graduated":true,"side":"buy"},{"i":14,"price":0.01045981,"floor":0.
|
|
241
|
+
const DATA = /*DATA*/{"run":"A simulated launch with a USDC quote at $1: 74 buys and 8 sells","quoteDecimals":6,"series":[{"i":0,"price":0.01,"floor":null,"graduated":false,"side":"open"},{"i":1,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":2,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":3,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":4,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":5,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":6,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":7,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":8,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":9,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":10,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":11,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":12,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":13,"price":0.01022274,"floor":0.01,"graduated":true,"side":"buy"},{"i":14,"price":0.01045981,"floor":0.01000702,"graduated":true,"side":"buy"},{"i":15,"price":0.01069961,"floor":0.01001356,"graduated":true,"side":"buy"},{"i":16,"price":0.01092692,"floor":0.01001968,"graduated":true,"side":"buy"},{"i":17,"price":0.01110845,"floor":0.01002545,"graduated":true,"side":"buy"},{"i":18,"price":0.0112915,"floor":0.0100309,"graduated":true,"side":"buy"},{"i":19,"price":0.01147605,"floor":0.01003607,"graduated":true,"side":"buy"},{"i":20,"price":0.0116621,"floor":0.01004098,"graduated":true,"side":"buy"},{"i":21,"price":0.01184832,"floor":0.01004568,"graduated":true,"side":"buy"},{"i":22,"price":0.0119884,"floor":0.01005016,"graduated":true,"side":"buy"},{"i":23,"price":0.01212932,"floor":0.01005447,"graduated":true,"side":"buy"},{"i":24,"price":0.01227106,"floor":0.0100586,"graduated":true,"side":"buy"},{"i":25,"price":0.01284634,"floor":0.01007293,"graduated":true,"side":"buy"},{"i":26,"price":0.01329322,"floor":0.01008562,"graduated":true,"side":"buy"},{"i":27,"price":0.01373598,"floor":0.01030198,"graduated":true,"side":"buy"},{"i":28,"price":0.01414542,"floor":0.01060907,"graduated":true,"side":"buy"},{"i":29,"price":0.01448348,"floor":0.01086261,"graduated":true,"side":"buy"},{"i":30,"price":0.01482555,"floor":0.01111917,"graduated":true,"side":"buy"},{"i":31,"price":0.01517165,"floor":0.01137874,"graduated":true,"side":"buy"},{"i":32,"price":0.01545607,"floor":0.01159206,"graduated":true,"side":"buy"},{"i":33,"price":0.0157178,"floor":0.01178835,"graduated":true,"side":"buy"},{"i":34,"price":0.01598174,"floor":0.01198631,"graduated":true,"side":"buy"},{"i":35,"price":0.01624789,"floor":0.01218592,"graduated":true,"side":"buy"},{"i":36,"price":0.01651626,"floor":0.0123872,"graduated":true,"side":"buy"},{"i":37,"price":0.01674282,"floor":0.01255712,"graduated":true,"side":"buy"},{"i":38,"price":0.01694468,"floor":0.01270851,"graduated":true,"side":"buy"},{"i":39,"price":0.01714776,"floor":0.01286082,"graduated":true,"side":"buy"},{"i":40,"price":0.01735205,"floor":0.01301404,"graduated":true,"side":"buy"},{"i":41,"price":0.01755756,"floor":0.01316817,"graduated":true,"side":"buy"},{"i":42,"price":0.01776429,"floor":0.01332322,"graduated":true,"side":"buy"},{"i":43,"price":0.01797224,"floor":0.01347918,"graduated":true,"side":"buy"},{"i":44,"price":0.01815632,"floor":0.01361724,"graduated":true,"side":"buy"},{"i":45,"price":0.01831214,"floor":0.01373411,"graduated":true,"side":"buy"},{"i":46,"price":0.01846863,"floor":0.01385147,"graduated":true,"side":"buy"},{"i":47,"price":0.0186258,"floor":0.01396935,"graduated":true,"side":"buy"},{"i":48,"price":0.01878363,"floor":0.01408772,"graduated":true,"side":"buy"},{"i":49,"price":0.01859303,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":50,"price":0.01841113,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":51,"price":0.01823746,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":52,"price":0.01806707,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":53,"price":0.01853992,"floor":0.01408772,"graduated":true,"side":"buy"},{"i":54,"price":0.01901433,"floor":0.01426075,"graduated":true,"side":"buy"},{"i":55,"price":0.01949479,"floor":0.0146211,"graduated":true,"side":"buy"},{"i":56,"price":0.01990367,"floor":0.01492776,"graduated":true,"side":"buy"},{"i":57,"price":0.02026771,"floor":0.01520078,"graduated":true,"side":"buy"},{"i":58,"price":0.02063506,"floor":0.0154763,"graduated":true,"side":"buy"},{"i":59,"price":0.02100574,"floor":0.0157543,"graduated":true,"side":"buy"},{"i":60,"price":0.02137974,"floor":0.0160348,"graduated":true,"side":"buy"},{"i":61,"price":0.02166974,"floor":0.01625231,"graduated":true,"side":"buy"},{"i":62,"price":0.02195119,"floor":0.01646339,"graduated":true,"side":"buy"},{"i":63,"price":0.02223446,"floor":0.01667585,"graduated":true,"side":"buy"},{"i":64,"price":0.02251957,"floor":0.01688968,"graduated":true,"side":"buy"},{"i":65,"price":0.0228065,"floor":0.01710487,"graduated":true,"side":"buy"},{"i":66,"price":0.02309526,"floor":0.01732144,"graduated":true,"side":"buy"},{"i":67,"price":0.02336672,"floor":0.01752504,"graduated":true,"side":"buy"},{"i":68,"price":0.02358335,"floor":0.01768751,"graduated":true,"side":"buy"},{"i":69,"price":0.02346715,"floor":0.01768751,"graduated":true,"side":"sell"},{"i":70,"price":0.02335372,"floor":0.01768751,"graduated":true,"side":"sell"},{"i":71,"price":0.02321907,"floor":0.01768751,"graduated":true,"side":"sell"},{"i":72,"price":0.02307369,"floor":0.01768751,"graduated":true,"side":"sell"},{"i":73,"price":0.02335063,"floor":0.01768751,"graduated":true,"side":"buy"},{"i":74,"price":0.02356718,"floor":0.01768751,"graduated":true,"side":"buy"},{"i":75,"price":0.02378474,"floor":0.01783855,"graduated":true,"side":"buy"},{"i":76,"price":0.02400331,"floor":0.01800248,"graduated":true,"side":"buy"},{"i":77,"price":0.02422288,"floor":0.01816716,"graduated":true,"side":"buy"},{"i":78,"price":0.02444346,"floor":0.0183326,"graduated":true,"side":"buy"},{"i":79,"price":0.02466505,"floor":0.01849879,"graduated":true,"side":"buy"},{"i":80,"price":0.02488764,"floor":0.01866573,"graduated":true,"side":"buy"},{"i":81,"price":0.02511124,"floor":0.01883343,"graduated":true,"side":"buy"},{"i":82,"price":0.02533585,"floor":0.01900189,"graduated":true,"side":"buy"}]}/*END*/;
|
|
242
242
|
const SUPPLY = 1e9; // a FLOOR launch mints 1B tokens; market cap = price x total supply
|
|
243
243
|
const pts = DATA.series;
|
|
244
244
|
|
|
@@ -343,7 +343,7 @@ function show() {
|
|
|
343
343
|
draw(n);
|
|
344
344
|
$("sPrice").textContent = fmtP(p.price);
|
|
345
345
|
$("sFloor").textContent = p.floor === null ? "—" : fmtP(p.floor);
|
|
346
|
-
$("
|
|
346
|
+
$("sMaxLoss").textContent = p.floor === null ? "—" : Math.round(100 - (100 * p.floor) / p.price) + "%";
|
|
347
347
|
$("sMcap").textContent = fmtP(p.price * SUPPLY);
|
|
348
348
|
const ph = $("phase");
|
|
349
349
|
ph.textContent = p.graduated ? "Graduated" : "Bonding";
|
package/package.json
CHANGED
package/src/abi/evm.gen.ts
CHANGED
|
@@ -17,7 +17,7 @@ export const EVM_EVENT_SCHEMAS: readonly EvmEventSchema[] = [
|
|
|
17
17
|
{ 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}] },
|
|
18
18
|
{ name: "OptedIn", signature: "OptedIn(address)", topic: "0x25f9c685db8e2630204f5e7c890a95f58852ccac883a9d96f44a72b777b06c59", params: [{"name":"a","type":"address","indexed":true}] },
|
|
19
19
|
{ 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}] },
|
|
20
|
-
{ name: "Claimed", signature: "Claimed(address,address,address,
|
|
20
|
+
{ 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}] },
|
|
21
21
|
{ 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}] },
|
|
22
22
|
{ 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}] },
|
|
23
23
|
{ 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}] },
|
|
@@ -106,6 +106,7 @@ export const EVM_ERRORS: readonly ProgramErrorRow[] = [
|
|
|
106
106
|
{ chain: "evm", name: "PresetDisabled", message: "PresetDisabled", code: null, selector: "0x5518d9cd", signature: "PresetDisabled()" },
|
|
107
107
|
{ chain: "evm", name: "PresetIdNotNext", message: "PresetIdNotNext", code: null, selector: "0x9b5a5243", signature: "PresetIdNotNext()" },
|
|
108
108
|
{ chain: "evm", name: "PresetInvalid", message: "PresetInvalid", code: null, selector: "0x46f63096", signature: "PresetInvalid()" },
|
|
109
|
+
{ chain: "evm", name: "PriceOrder", message: "PriceOrder", code: null, selector: "0x6b2c148b", signature: "PriceOrder()" },
|
|
109
110
|
{ chain: "evm", name: "QuoteDisabled", message: "QuoteDisabled", code: null, selector: "0x31ccdc5d", signature: "QuoteDisabled()" },
|
|
110
111
|
{ chain: "evm", name: "QuoteListed", message: "QuoteListed", code: null, selector: "0xe6faf0c2", signature: "QuoteListed()" },
|
|
111
112
|
{ chain: "evm", name: "QuoteNotListed", message: "QuoteNotListed", code: null, selector: "0x06ff137a", signature: "QuoteNotListed()" },
|
|
@@ -120,6 +121,7 @@ export const EVM_ERRORS: readonly ProgramErrorRow[] = [
|
|
|
120
121
|
{ chain: "evm", name: "SafeERC20FailedOperation", message: "SafeERC20FailedOperation", code: null, selector: "0x5274afe7", signature: "SafeERC20FailedOperation(address)" },
|
|
121
122
|
{ chain: "evm", name: "SellTooLarge", message: "SellTooLarge", code: null, selector: "0x8e4d208f", signature: "SellTooLarge()" },
|
|
122
123
|
{ chain: "evm", name: "SlippageExceeded", message: "SlippageExceeded", code: null, selector: "0x8199f5f3", signature: "SlippageExceeded()" },
|
|
124
|
+
{ chain: "evm", name: "SqrtRange", message: "SqrtRange", code: null, selector: "0x1e523888", signature: "SqrtRange()" },
|
|
123
125
|
{ chain: "evm", name: "StringsInsufficientHexLength", message: "StringsInsufficientHexLength", code: null, selector: "0xe22e27eb", signature: "StringsInsufficientHexLength(uint256,uint256)" },
|
|
124
126
|
{ chain: "evm", name: "SwapDataNotEmpty", message: "SwapDataNotEmpty", code: null, selector: "0x8821f518", signature: "SwapDataNotEmpty()" },
|
|
125
127
|
{ chain: "evm", name: "SwapFailed", message: "SwapFailed", code: null, selector: "0xff9fa595", signature: "SwapFailed(bytes)" },
|
|
@@ -135,5 +137,8 @@ export const EVM_ERRORS: readonly ProgramErrorRow[] = [
|
|
|
135
137
|
{ chain: "evm", name: "UnknownLaunch", message: "UnknownLaunch", code: null, selector: "0xf6806bf8", signature: "UnknownLaunch()" },
|
|
136
138
|
{ chain: "evm", name: "UUPSUnauthorizedCallContext", message: "UUPSUnauthorizedCallContext", code: null, selector: "0xe07c8dba", signature: "UUPSUnauthorizedCallContext()" },
|
|
137
139
|
{ chain: "evm", name: "UUPSUnsupportedProxiableUUID", message: "UUPSUnsupportedProxiableUUID", code: null, selector: "0xaa1d49a4", signature: "UUPSUnsupportedProxiableUUID(bytes32)" },
|
|
140
|
+
{ chain: "evm", name: "VaultShareOutOfRange", message: "VaultShareOutOfRange", code: null, selector: "0xdb8df2d8", signature: "VaultShareOutOfRange()" },
|
|
141
|
+
{ chain: "evm", name: "Zero", message: "Zero", code: null, selector: "0xf4560403", signature: "Zero()" },
|
|
138
142
|
{ chain: "evm", name: "ZeroAddress", message: "ZeroAddress", code: null, selector: "0xd92e233d", signature: "ZeroAddress()" },
|
|
143
|
+
{ chain: "evm", name: "ZeroLiquidity", message: "ZeroLiquidity", code: null, selector: "0x10074548", signature: "ZeroLiquidity()" },
|
|
139
144
|
];
|
package/src/abi/solana.gen.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface SolanaEventSchema {
|
|
|
12
12
|
|
|
13
13
|
export const SOLANA_EVENT_SCHEMAS: readonly SolanaEventSchema[] = [
|
|
14
14
|
{ 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"]] },
|
|
15
|
-
{ name: "Graduated", discriminator: "33f142328cf59cc0", source: "v1", fields: [["launch","pubkey"],["
|
|
15
|
+
{ name: "Graduated", discriminator: "33f142328cf59cc0", source: "v1", fields: [["launch","pubkey"],["windowPriceX64","u128"],["windowRaised","u64"],["windowTokens","u64"],["slot","u64"],["ts","i64"],["priceX64","u128"]] },
|
|
16
16
|
{ name: "PotsSwept", discriminator: "33480c25b092b903", source: "v1", fields: [["launch","pubkey"],["amount","u64"],["reason","u8"]] },
|
|
17
17
|
{ 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?"]] },
|
|
18
18
|
{ 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"]] },
|
package/src/client/evm/index.ts
CHANGED
|
@@ -80,6 +80,20 @@ export function createEvmClient(opts: FloorClientOptions<"evm">): EvmFloorClient
|
|
|
80
80
|
throw decodeEvmProgramError(e) ?? new FloorError("Transport", `eth_call to ${c.to} failed`, { source: "sdk", cause: e });
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
+
|
|
84
|
+
const approvals = async (token: string, owner: string, amount: bigint): Promise<EvmCall[]> => {
|
|
85
|
+
let have: bigint | null = null;
|
|
86
|
+
try {
|
|
87
|
+
const pad = (a: string): string => a.toLowerCase().replace(/^0x/, "").padStart(64, "0");
|
|
88
|
+
const out = await transport.rpc.call({ to: token, data: `0xdd62ed3e${pad(owner)}${pad(floorAmm)}` } as EvmCall);
|
|
89
|
+
if (typeof out === "string" && /^0x[0-9a-fA-F]{64}$/.test(out)) have = BigInt(out);
|
|
90
|
+
} catch {
|
|
91
|
+
have = null;
|
|
92
|
+
}
|
|
93
|
+
if (have !== null && have >= amount) return [];
|
|
94
|
+
if (have !== null && have > 0n) return [approveCall(token, floorAmm, 0n), approveCall(token, floorAmm, amount)];
|
|
95
|
+
return [approveCall(token, floorAmm, amount)];
|
|
96
|
+
};
|
|
83
97
|
const tx = (calls: EvmCall[]): EvmTx => ({ family: "evm", chainId, calls });
|
|
84
98
|
const launchIdOf = (launch: bigint): bigint => {
|
|
85
99
|
if (typeof launch !== "bigint" || launch <= 0n) throw bad("launch: an EVM launch is its launchId, a bigint > 0");
|
|
@@ -167,14 +181,14 @@ export function createEvmClient(opts: FloorClientOptions<"evm">): EvmFloorClient
|
|
|
167
181
|
const launchId = launchIdOf(p.launch);
|
|
168
182
|
const { quote } = await launchState(launchId);
|
|
169
183
|
const buy = buyCall({ floorAmm, quote, launchId, amountIn: p.amountIn, minTokensOut: p.minOut, to: p.recipient ?? p.trader, ...(p.deadline !== undefined ? { deadline: p.deadline } : {}) });
|
|
170
|
-
return tx(quote.toLowerCase() === NATIVE_QUOTE ? [buy] : [
|
|
184
|
+
return tx(quote.toLowerCase() === NATIVE_QUOTE ? [buy] : [...(await approvals(quote, p.trader, p.amountIn)), buy]);
|
|
171
185
|
}),
|
|
172
186
|
|
|
173
187
|
buildSell: (p) => guard(async () => {
|
|
174
188
|
const launchId = launchIdOf(p.launch);
|
|
175
189
|
const sell = sellCall({ floorAmm, launchId, tokensIn: p.tokensIn, minQuoteOut: p.minOut, to: p.recipient ?? p.trader, ...(p.deadline !== undefined ? { deadline: p.deadline } : {}) });
|
|
176
190
|
const { token } = await launchState(launchId);
|
|
177
|
-
return tx([
|
|
191
|
+
return tx([...(await approvals(token, p.trader, p.tokensIn)), sell]);
|
|
178
192
|
}),
|
|
179
193
|
|
|
180
194
|
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.ts";
|
|
9
9
|
import { sCirc } from "../../math/v2/supply.ts";
|
|
10
10
|
import { CLAIM_SHARE_BOUGHT, CLAIM_TEAM_BUY, CLAIM_TRADER_REF } from "../../solana/floor/instructions.ts";
|
|
11
|
-
import { FLOOR_AMM_PROGRAM_ID, configPda, launchPda, refOwedPda, refOwedVault, teamSlotPda, traderRefEscrow, traderRefPda } from "../../solana/floor/program.ts";
|
|
11
|
+
import { FLOOR_AMM_PROGRAM_ID, configPda, launchPda, refOwedPda, refOwedVault, teamSlotPda, traderLinkPda, traderRefEscrow, traderRefPda } from "../../solana/floor/program.ts";
|
|
12
12
|
import { MAX_COMPUTE_UNIT_LIMIT, computeUnitLimitInstruction } from "../../solana/instruction.ts";
|
|
13
13
|
import type { Instruction } from "../../solana/instruction.ts";
|
|
14
14
|
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, WSOL_MINT, associatedTokenAddress } from "../../solana/pda.ts";
|
|
@@ -99,14 +99,23 @@ export function createSolanaClient(opts: FloorClientOptions<"solana">): FloorCli
|
|
|
99
99
|
return { address, l };
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
async function
|
|
102
|
+
async function quoteIsLaunchOf(l: LaunchV2Account): Promise<boolean> {
|
|
103
|
+
if (l.quoteTokenProgram !== TOKEN_2022_PROGRAM_ID) return false;
|
|
104
|
+
const a = await get(launchPda(l.quoteMint, pid)[0]);
|
|
105
|
+
return a !== null && a.owner === pid;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function tradeAccounts(address: string, l: LaunchV2Account, trader: string, baseOwner: string, quoteOwner: string, isBuy: boolean): Promise<TradeAccountsV2 & { programId: string; hookProgramId: string }> {
|
|
103
109
|
const ref = traderRefPda(trader, l.quoteMint, pid)[0];
|
|
104
|
-
const
|
|
110
|
+
const linked = (await get(traderLinkPda(trader, pid)[0])) !== null;
|
|
111
|
+
const hasRef = linked || (await get(ref)) !== null;
|
|
112
|
+
const out = isBuy ? baseOwner : quoteOwner;
|
|
105
113
|
return {
|
|
106
114
|
programId: pid, hookProgramId: hid, trader, launch: address, baseMint: l.baseMint, quoteMint: l.quoteMint, tokenVault: l.tokenVault, quoteVault: l.quoteVault,
|
|
107
115
|
traderBase: associatedTokenAddress(baseOwner, l.baseMint, TOKEN_2022_PROGRAM_ID), traderQuote: associatedTokenAddress(quoteOwner, l.quoteMint, l.quoteTokenProgram),
|
|
108
116
|
quoteTokenProgram: l.quoteTokenProgram, traderRef: hasRef ? ref : null, escrow: hasRef ? traderRefEscrow(ref, l.quoteMint, l.quoteTokenProgram) : null,
|
|
109
|
-
baseOwner, quoteOwner,
|
|
117
|
+
baseOwner, quoteOwner, quoteIsLaunch: await quoteIsLaunchOf(l),
|
|
118
|
+
...(linked ? { user: trader, recipient: out !== trader ? out : null } : {}),
|
|
110
119
|
};
|
|
111
120
|
}
|
|
112
121
|
|
|
@@ -188,7 +197,7 @@ export function createSolanaClient(opts: FloorClientOptions<"solana">): FloorCli
|
|
|
188
197
|
if (p.amountIn <= 0n) throw bad("amountIn must be > 0");
|
|
189
198
|
const { address, l } = await launchOf(p.launch);
|
|
190
199
|
const owner = p.recipient ?? p.trader;
|
|
191
|
-
const a = await tradeAccounts(address, l, p.trader, owner, p.trader);
|
|
200
|
+
const a = await tradeAccounts(address, l, p.trader, owner, p.trader, true);
|
|
192
201
|
|
|
193
202
|
const hasPosition = owner !== p.trader || (await get(holderPositionPda(address, owner, hid)[0])) !== null;
|
|
194
203
|
const wsol = await wsolLegs(l, p.trader, p.trader);
|
|
@@ -206,7 +215,7 @@ export function createSolanaClient(opts: FloorClientOptions<"solana">): FloorCli
|
|
|
206
215
|
if (p.tokensIn <= 0n) throw bad("tokensIn must be > 0");
|
|
207
216
|
const { address, l } = await launchOf(p.launch);
|
|
208
217
|
const to = p.recipient ?? p.trader;
|
|
209
|
-
const a = await tradeAccounts(address, l, p.trader, p.trader, to);
|
|
218
|
+
const a = await tradeAccounts(address, l, p.trader, p.trader, to, false);
|
|
210
219
|
const wsol = await wsolLegs(l, to, p.trader);
|
|
211
220
|
const instructions: Instruction[] = [
|
|
212
221
|
computeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT),
|
|
@@ -219,28 +228,36 @@ export function createSolanaClient(opts: FloorClientOptions<"solana">): FloorCli
|
|
|
219
228
|
|
|
220
229
|
claim: (p: ClaimParams<"solana">): Promise<SolanaTx> => guard(async () => {
|
|
221
230
|
const tok = (p.types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
|
|
222
|
-
const launches: ClaimLaunchV2[] = [];
|
|
223
231
|
let qtp: string | null = null;
|
|
224
|
-
|
|
232
|
+
let qIsLaunch = false;
|
|
233
|
+
|
|
234
|
+
const read = await Promise.all(p.launches.map(async (mint) => {
|
|
225
235
|
const { address, l } = await launchOf(mint);
|
|
226
236
|
if (l.quoteMint !== p.quote) throw bad(`launch ${mint} trades in ${l.quoteMint}, not ${p.quote}`);
|
|
227
|
-
qtp = l.quoteTokenProgram;
|
|
228
237
|
const slot = teamSlotPda(address, pid)[0];
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
238
|
+
const [isLaunch, slotAcc] = await Promise.all([quoteIsLaunchOf(l), get(slot)]);
|
|
239
|
+
return { mint, address, l, slot, isLaunch, slotAcc };
|
|
240
|
+
}));
|
|
241
|
+
const launches: ClaimLaunchV2[] = read.map(({ address, l, slot, slotAcc }) => ({
|
|
242
|
+
launch: address, quoteVault: l.quoteVault, teamSlot: slotAcc !== null ? slot : null, baseMint: l.baseMint,
|
|
243
|
+
...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
|
|
244
|
+
}));
|
|
245
|
+
const last = read.at(-1);
|
|
246
|
+
if (last !== undefined) {
|
|
247
|
+
qtp = last.l.quoteTokenProgram;
|
|
248
|
+
qIsLaunch = last.isLaunch;
|
|
233
249
|
}
|
|
234
250
|
if (qtp === null) {
|
|
235
251
|
const m = await get(p.quote);
|
|
236
252
|
if (m === null) throw new FloorError("BadAccount", `no quote mint ${p.quote}`, { source: "sdk" });
|
|
237
253
|
qtp = m.owner;
|
|
254
|
+
qIsLaunch = await quoteIsLaunchOf({ quoteMint: p.quote, quoteTokenProgram: qtp } as LaunchV2Account);
|
|
238
255
|
}
|
|
239
256
|
const ro = (p.types & CLAIM_TRADER_REF) !== 0 ? refOwedPda(p.wallet, p.quote, pid)[0] : null;
|
|
240
257
|
const claim = claimInstructionV2({
|
|
241
258
|
...ids, sender: p.wallet, wallet: p.wallet, quoteMint: p.quote, quoteTokenProgram: qtp, destination: associatedTokenAddress(p.wallet, p.quote, qtp),
|
|
242
259
|
config: configPda(pid)[0], refOwed: ro, refOwedVault: ro ? refOwedVault(ro, p.quote, qtp) : null, types: p.types, launches,
|
|
243
|
-
unwrap: p.quote === WSOL_MINT && qtp === TOKEN_PROGRAM_ID,
|
|
260
|
+
unwrap: p.quote === WSOL_MINT && qtp === TOKEN_PROGRAM_ID, quoteIsLaunch: qIsLaunch,
|
|
244
261
|
});
|
|
245
262
|
return { family: "solana", instructions: [computeUnitLimitInstruction(CLAIM_COMPUTE_UNIT_LIMIT_V2), claim] };
|
|
246
263
|
}),
|
package/src/client/types.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Instruction } from "../solana/instruction.ts";
|
|
|
4
4
|
import type { EvmCall } from "../v2/evm.ts";
|
|
5
5
|
import type { FloorError } from "../errors.ts";
|
|
6
6
|
|
|
7
|
-
export type FloorFamily = "solana" | "evm";
|
|
7
|
+
export type FloorFamily = "solana" | "evm" | "ton";
|
|
8
8
|
|
|
9
9
|
export interface SolanaChain {
|
|
10
10
|
family: "solana";
|