@floorlaunchpad/sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +61 -0
- package/README.md +33 -2
- package/dist/adapter.d.ts +28 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +2 -0
- package/dist/adapter.js.map +1 -0
- package/dist/chain.d.ts +23 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +25 -0
- package/dist/chain.js.map +1 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +43 -0
- package/dist/client.js.map +1 -0
- package/dist/dex-adapter.d.ts +228 -0
- package/dist/dex-adapter.d.ts.map +1 -0
- package/dist/dex-adapter.js +407 -0
- package/dist/dex-adapter.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/quotes.d.ts +12 -0
- package/dist/quotes.d.ts.map +1 -0
- package/dist/quotes.gen.d.ts +8 -0
- package/dist/quotes.gen.d.ts.map +1 -0
- package/dist/quotes.gen.js +2170 -0
- package/dist/quotes.gen.js.map +1 -0
- package/dist/quotes.js +24 -0
- package/dist/quotes.js.map +1 -0
- package/dist/types.d.ts +111 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -4
- package/src/adapter.ts +20 -0
- package/src/chain.ts +39 -0
- package/src/client.ts +41 -0
- package/src/dex-adapter.ts +477 -0
- package/src/index.ts +6 -0
- package/src/quotes.gen.ts +2170 -0
- package/src/quotes.ts +29 -0
- package/src/types.ts +115 -0
package/src/quotes.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { chainKey, type ChainRef } from './chain.js';
|
|
2
|
+
import { APPROVED_QUOTE_TOKENS } from './quotes.gen.js';
|
|
3
|
+
|
|
4
|
+
export { APPROVED_QUOTE_TOKENS };
|
|
5
|
+
|
|
6
|
+
const ZERO_EVM = '0x0000000000000000000000000000000000000000';
|
|
7
|
+
const WSOL = 'So11111111111111111111111111111111111111112';
|
|
8
|
+
|
|
9
|
+
const sets = new Map<string, Map<string, string | null>>(
|
|
10
|
+
Object.entries(APPROVED_QUOTE_TOKENS).map(([key, rows]) => [key, new Map(rows.map(([address, symbol]) => [address, symbol]))]),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const norm = (ref: ChainRef, address: string): string => (ref.family === 'evm' ? address.toLowerCase() : address);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether FLOOR shows a launch quoted in `quote` on `chain`: the native coin (`null`, the zero address on EVM, wSOL on
|
|
17
|
+
* Solana) always, a token when it is on the chain's list. A chain with no list approves no token. Launches quoted in another
|
|
18
|
+
* FLOOR launch's token can also be shown by lineage, which this does not decide.
|
|
19
|
+
*/
|
|
20
|
+
export function isApprovedQuote(chain: ChainRef, quote: string | null): boolean {
|
|
21
|
+
if (quote === null) return true;
|
|
22
|
+
if (chain.family === 'evm' ? quote.toLowerCase() === ZERO_EVM : quote === WSOL) return true;
|
|
23
|
+
return sets.get(chainKey(chain))?.has(norm(chain, quote)) ?? false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The symbol FLOOR lists an approved quote token under, or `undefined` for a token not on the chain's list. */
|
|
27
|
+
export function approvedQuoteSymbol(chain: ChainRef, quote: string): string | null | undefined {
|
|
28
|
+
return sets.get(chainKey(chain))?.get(norm(chain, quote));
|
|
29
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { ChainRef } from './chain.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A launch is named by its chain and its token address. ⛔ The address is kept VERBATIM: a Solana
|
|
5
|
+
* mint is base58 and case-sensitive (a case-folded mint can decode to a different valid key), and an
|
|
6
|
+
* EVM address is compared case-insensitively but never rewritten here.
|
|
7
|
+
*/
|
|
8
|
+
export interface LaunchRef {
|
|
9
|
+
readonly chain: ChainRef;
|
|
10
|
+
readonly token: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Every amount is a bigint in the token's or the quote asset's smallest unit. Never a float. */
|
|
14
|
+
export type Amount = bigint;
|
|
15
|
+
|
|
16
|
+
/** `pending`: created, but the sale is not open or funded yet (no quote). */
|
|
17
|
+
export type LaunchPhase = 'pending' | 'bonding' | 'graduated';
|
|
18
|
+
|
|
19
|
+
/** What every chain can say about a launch. Chain-specific detail lives on `raw`. */
|
|
20
|
+
export interface Launch<Raw = unknown> {
|
|
21
|
+
readonly ref: LaunchRef;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly symbol: string;
|
|
24
|
+
readonly decimals: number;
|
|
25
|
+
readonly totalSupply: Amount;
|
|
26
|
+
/** The asset a launch is bought with: native (ETH, SOL…) or a token. */
|
|
27
|
+
readonly quote: { readonly address: string | null; readonly symbol: string; readonly decimals: number };
|
|
28
|
+
readonly phase: LaunchPhase;
|
|
29
|
+
/** The mode id (Custom 0, Moonshot 1, Cook 2, Bluechip 3, then presets appended). */
|
|
30
|
+
readonly mode: number;
|
|
31
|
+
/** `null` when the chain names no creator. */
|
|
32
|
+
readonly creator: string | null;
|
|
33
|
+
/** The published floor: WHOLE quote per WHOLE token, scaled by 1e18 (decimals already applied). `null` before one exists. */
|
|
34
|
+
readonly floorPriceX18: Amount | null;
|
|
35
|
+
readonly raw: Raw;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type Side = 'buy' | 'sell';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A quote. `amountIn` is what the trader pays; `amountOut` what they receive after every fee.
|
|
42
|
+
* ⛔ `fees` lists the trader's whole take or nothing: a partial list is refused at construction.
|
|
43
|
+
*/
|
|
44
|
+
export interface Quote {
|
|
45
|
+
readonly launch: LaunchRef;
|
|
46
|
+
readonly side: Side;
|
|
47
|
+
readonly amountIn: Amount;
|
|
48
|
+
readonly amountOut: Amount;
|
|
49
|
+
readonly fees: readonly FeePart[];
|
|
50
|
+
/** `false` when a fee part is an estimate (e.g. read at the pre-trade price); the totals still match `amountOut`. */
|
|
51
|
+
readonly feesExact: boolean;
|
|
52
|
+
/** Quote asset handed back because the trade could not use all of `amountIn` (a sale that sells out). */
|
|
53
|
+
readonly refund?: Amount;
|
|
54
|
+
/** `true` when this trade sells out the bonding sale and graduates the launch inside the same transaction. */
|
|
55
|
+
readonly graduates?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The most NATIVE currency (lamports, wei) the trade may take from the trader ON TOP of `amountIn` — e.g. on Solana the
|
|
58
|
+
* rent of the accounts a graduating buy creates, which the buy instruction bounds by this figure. The full wallet debit
|
|
59
|
+
* is at most `amountIn` (when the quote asset is native) + `maxExtraNative` + network fees. Absent when the trade has
|
|
60
|
+
* no such cost.
|
|
61
|
+
*/
|
|
62
|
+
readonly maxExtraNative?: Amount;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type FeePartKind =
|
|
66
|
+
| 'lp'
|
|
67
|
+
| 'floorSkim'
|
|
68
|
+
| 'creator'
|
|
69
|
+
| 'holder'
|
|
70
|
+
| 'floorPlatform'
|
|
71
|
+
/** Solana only: Carpenter's own protocol fee. */
|
|
72
|
+
| 'carpenterPlatform';
|
|
73
|
+
|
|
74
|
+
export interface FeePart {
|
|
75
|
+
readonly kind: FeePartKind;
|
|
76
|
+
/** In the quote asset's smallest unit. */
|
|
77
|
+
readonly amount: Amount;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One EVM call. */
|
|
81
|
+
export interface EvmCall {
|
|
82
|
+
readonly to: string;
|
|
83
|
+
readonly data: string;
|
|
84
|
+
readonly value: Amount;
|
|
85
|
+
/** A gas limit the builder knows a node's estimate can undershoot (e.g. a buy that graduates the sale). */
|
|
86
|
+
readonly gas?: Amount;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Everything one user action needs, in order, tagged by chain family. The caller's wallet signs and sends it.
|
|
91
|
+
*
|
|
92
|
+
* ONE WALLET PROMPT PER ACTION is the design on both chains:
|
|
93
|
+
* - Solana: `transactions` are signed together with ONE `signAllTransactions`, then sent in order, each confirmed before
|
|
94
|
+
* the next. Signing them one by one costs one prompt each.
|
|
95
|
+
* - EVM: `calls` (e.g. an approval, then the trade) go to the wallet as ONE EIP-5792 `wallet_sendCalls` batch where the
|
|
96
|
+
* wallet supports it (`sendEvmCalls` in `@floorlaunchpad/sdk-evm` does this and falls back to one transaction per call, one
|
|
97
|
+
* prompt each, where it does not). The SDK never asks for an off-chain signature (e.g. a Permit2 permit) when an
|
|
98
|
+
* on-chain call in the same batch does the job, so a batch is always one prompt.
|
|
99
|
+
*/
|
|
100
|
+
export type UnsignedTx =
|
|
101
|
+
| { readonly family: 'evm'; readonly chainId: number; readonly calls: readonly EvmCall[] }
|
|
102
|
+
/** One or more serialized (unsigned) Solana transactions, base64, in send order. */
|
|
103
|
+
| { readonly family: 'solana'; readonly cluster: string; readonly transactions: readonly string[] };
|
|
104
|
+
|
|
105
|
+
export interface TradeParams {
|
|
106
|
+
readonly launch: LaunchRef;
|
|
107
|
+
readonly side: Side;
|
|
108
|
+
/** Exact input: quote asset on a buy, tokens on a sell. */
|
|
109
|
+
readonly amountIn: Amount;
|
|
110
|
+
/** The least the trader accepts. Must be > 0. */
|
|
111
|
+
readonly minAmountOut: Amount;
|
|
112
|
+
readonly trader: string;
|
|
113
|
+
/** Unix seconds after which the trade must revert, where the venue supports one. */
|
|
114
|
+
readonly deadline?: bigint;
|
|
115
|
+
}
|