@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
@@ -38,17 +38,24 @@ export interface ChainRow {
38
38
  name: ChainName;
39
39
 
40
40
  label: string;
41
- family: "solana" | "evm";
41
+ family: "solana" | "evm" | "ton";
42
42
  v2DayOne: boolean;
43
43
  chainId?: number;
44
44
  cluster?: string;
45
+
46
+ network?: string;
47
+ globalId?: number;
48
+
49
+ nativeDecimals?: number;
45
50
  native: string;
46
51
 
47
52
  nativeName: string;
48
53
 
49
54
  floorAmmAddress?: string | null;
55
+
56
+ tonFactoryAddress?: string | null;
50
57
  rpcEnv: string;
51
- soak: { name?: string; chainId?: number; cluster?: string; rpcEnv: string };
58
+ soak: { name?: string; chainId?: number; cluster?: string; network?: string; globalId?: number; rpcEnv: string };
52
59
  explorer: ExplorerRow;
53
60
  quotes: readonly QuoteRow[];
54
61
  }
@@ -110,9 +110,40 @@ export const CHAIN_REGISTRY = [
110
110
  },
111
111
  "finality": "finalized",
112
112
  "reorgWindow": 65
113
+ },
114
+ {
115
+ "slug": "elysium",
116
+ "label": "Elysium",
117
+ "family": "evm",
118
+ "v2DayOne": true,
119
+ "chainId": 99901,
120
+ "soakChainId": 99801,
121
+ "native": {
122
+ "name": "Hype",
123
+ "symbol": "HYPE"
124
+ },
125
+ "finality": "safe",
126
+ "reorgWindow": 3400
127
+ },
128
+ {
129
+ "slug": "ton",
130
+ "label": "TON",
131
+ "family": "ton",
132
+ "v2DayOne": false,
133
+ "network": "mainnet",
134
+ "globalId": -239,
135
+ "soakNetwork": "testnet",
136
+ "soakGlobalId": -3,
137
+ "native": {
138
+ "name": "Gram",
139
+ "symbol": "GRAM",
140
+ "decimals": 9
141
+ }
113
142
  }
114
143
  ] as const;
115
144
 
116
- export const CHAIN_SLUGS = ["solana","ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm"] as const;
145
+ export const CHAIN_SLUGS = ["solana","ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm","elysium","ton"] as const;
146
+
147
+ export const EVM_CHAIN_SLUGS = ["ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm","elysium"] as const;
117
148
 
118
- export const EVM_CHAIN_SLUGS = ["ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm"] as const;
149
+ export const TON_CHAIN_SLUGS = ["ton"] as const;
@@ -24,11 +24,12 @@ export interface SolLaunchCreatedFields {
24
24
  }
25
25
  export interface SolGraduatedFields {
26
26
  launch: string;
27
- priceX64: bigint;
27
+ windowPriceX64: bigint;
28
28
  windowRaised: bigint;
29
29
  windowTokens: bigint;
30
30
  slot: bigint;
31
31
  ts: bigint;
32
+ priceX64: bigint;
32
33
  }
33
34
  export interface SolPotsSweptFields {
34
35
  launch: string;
package/src/evm/chains.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { bytesToHex, checksumAddress, create2Address, encodeAbi, hexToBytes } from "./abi.ts";
4
4
  import { keccak256 } from "./keccak.ts";
5
- import type { ZapFamily } from "./zap.ts";
5
+ import type { ZapFamily, ZapUrFork } from "./zap.ts";
6
6
  import { CHAIN_REGISTRY, EVM_CHAIN_SLUGS } from "../config/registry.gen.ts";
7
7
 
8
8
  export type ChainKey = (typeof EVM_CHAIN_SLUGS)[number];
@@ -18,6 +18,12 @@ export interface ZapRouter {
18
18
  optional: boolean;
19
19
 
20
20
  forkEncoding?: boolean;
21
+
22
+ urFork?: ZapUrFork;
23
+
24
+ zap: string | null;
25
+
26
+ floorRouter: string;
21
27
  }
22
28
 
23
29
  export interface EvmChain {
@@ -42,79 +48,152 @@ function strict(a: string): string {
42
48
  return c;
43
49
  }
44
50
 
45
- const r = (slot: string, amm: string, router: string, family: ZapFamily, confidence: ZapRouter["confidence"], optional = false, forkEncoding = false): ZapRouter => ({
51
+ const UR_FORK_OF_SLOT: Readonly<Record<string, ZapUrFork>> = { "aerodrome-ur": "aerodrome", "pancake-ur": "pancake", "ramses-ur": "ramses" };
52
+ function urForkOf(slot: string): ZapUrFork {
53
+ const f = UR_FORK_OF_SLOT[slot];
54
+ if (!f) throw new RangeError(`the UR fork row ${slot} names no fork`);
55
+ return f;
56
+ }
57
+
58
+ type ZapRouterSpec = Omit<ZapRouter, "zap" | "floorRouter">;
59
+
60
+ const r = (slot: string, amm: string, router: string, family: ZapFamily, confidence: ZapRouter["confidence"], optional = false, forkEncoding = false): ZapRouterSpec => ({
46
61
  slot,
47
62
  amm,
48
63
  router: strict(router),
49
64
  family,
50
65
  confidence,
51
66
  optional,
52
- ...(forkEncoding ? { forkEncoding } : {}),
67
+ ...(forkEncoding ? { forkEncoding, urFork: urForkOf(slot) } : {}),
53
68
  });
54
69
 
70
+ export const FLOOR_ZAP_ADDRESSES: Readonly<Record<ChainKey, Readonly<Record<string, string>>>> = {
71
+ ethereum: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
72
+ base: {
73
+ "aerodrome-ur": strict("0xD8329A195F26c27A911B5CE697B11947984dc0d1"),
74
+ "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
75
+ "pancake-ur": strict("0xE4335AaC829a788bb6988A372edfe3Cda41B0931"),
76
+ },
77
+ bsc: {
78
+ "pancake-ur": strict("0xE4335AaC829a788bb6988A372edfe3Cda41B0931"),
79
+ "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
80
+ },
81
+ arbitrum: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
82
+ hyperevm: {
83
+ prjx: strict("0x02E658B2B205F76850Cf6d584477A58cD797e46a"),
84
+ nest: strict("0x93aC608AA016271BBB92924C3838a0b550c34ce1"),
85
+ "ramses-ur": strict("0x4b22d4b3F104D76aB92A2CA4E5E4A08A27F18f52"),
86
+ hyperswap: strict("0x782DB7e687E16Bfe00C9a0CE41A76A7cC507566F"),
87
+ },
88
+ robinhood: {
89
+ "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
90
+ "ramses-ur": strict("0x4b22d4b3F104D76aB92A2CA4E5E4A08A27F18f52"),
91
+ },
92
+ arc: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
93
+ elysium: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
94
+ };
95
+
96
+ export const FLOOR_ROUTER_DEPLOYER = strict("0x3e70158e54E91d2984c0F3B66ce2cE730d1E0e11");
97
+
98
+ const ROUTER_PROXY_INITCODE = "0x67363d3d37363d34f03d5260086018f3";
99
+
100
+ function slotWord(slot: string): Uint8Array {
101
+ const b = new TextEncoder().encode(slot);
102
+ if (b.length === 0 || b.length > 32) throw new RangeError(`a router slot is 1..32 bytes: ${JSON.stringify(slot)}`);
103
+ const w = new Uint8Array(32);
104
+ w.set(b);
105
+ return w;
106
+ }
107
+
108
+ export function floorRouterAddress(slot: string, deployer: string = FLOOR_ROUTER_DEPLOYER): string {
109
+ const s = keccak256(encodeAbi(["string", "bytes32"], ["floor-router.v1.FloorRouter", bytesToHex(slotWord(slot))]));
110
+ const proxy = create2Address({ deployer, salt: s, initCode: ROUTER_PROXY_INITCODE });
111
+
112
+ return checksumAddress(bytesToHex(keccak256(hexToBytes("0xd694" + proxy.slice(2) + "01")).slice(12)));
113
+ }
114
+
115
+ function withBookedZaps(key: ChainKey, rows: readonly ZapRouterSpec[]): ZapRouter[] {
116
+ const book = FLOOR_ZAP_ADDRESSES[key];
117
+ return rows.map((row) => ({ ...row, zap: book[row.slot] ?? null, floorRouter: floorRouterAddress(row.slot) }));
118
+ }
119
+
55
120
  const UNISWAP_UR = "uniswap-ur";
56
121
 
57
122
  const ROUTES: Record<ChainKey, Omit<EvmChain, "key" | "chainId" | "name" | "nativeSymbol">> = {
58
123
  ethereum: {
59
124
  wrappedNative: strict("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
60
- zapRouters: [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x4C82D1fBFe28C977cBB58D8C7FF8FCF9F70a2cCA", "uniswap-ur", "HIGH")],
125
+ zapRouters: withBookedZaps("ethereum", [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x4C82D1fBFe28C977cBB58D8C7FF8FCF9F70a2cCA", "uniswap-ur", "HIGH")]),
61
126
  notes: [],
62
127
  },
63
128
  base: {
64
129
  wrappedNative: strict("0x4200000000000000000000000000000000000006"),
65
- zapRouters: [
130
+ zapRouters: withBookedZaps("base", [
66
131
  r("aerodrome-ur", "Aerodrome V1 + Slipstream", "0xC5b6786D7B64767D775877b0B6A319AD946B11B5", "uniswap-ur", "HIGH", false, true),
67
132
  r(UNISWAP_UR, "Uniswap v2/v3/v4", "0xFdf682F51FE81Aa4898F0AE2163d8A55c127fbC7", "uniswap-ur", "HIGH"),
68
133
  r("pancake-ur", "PancakeSwap V3 / Infinity", "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB", "uniswap-ur", "HIGH", true, true),
69
- ],
134
+ ]),
70
135
  notes: [],
71
136
  },
72
137
  bsc: {
73
138
  wrappedNative: strict("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"),
74
- zapRouters: [
139
+ zapRouters: withBookedZaps("bsc", [
75
140
  r("pancake-ur", "PancakeSwap V2 / V3 / Infinity", "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB", "uniswap-ur", "HIGH", false, true),
76
141
  r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH"),
77
- ],
142
+ ]),
78
143
  notes: ["⚠ 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD is Uniswap's UR v1.2, NOT PancakeSwap's: never use it as Pancake's."],
79
144
  },
80
145
  arbitrum: {
81
146
  wrappedNative: strict("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"),
82
- zapRouters: [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH")],
147
+ zapRouters: withBookedZaps("arbitrum", [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH")]),
83
148
  notes: [],
84
149
  },
85
150
  hyperevm: {
86
151
  maxFloorHops: 2,
87
152
  wrappedNative: strict("0x5555555555555555555555555555555555555555"),
88
- zapRouters: [
153
+ zapRouters: withBookedZaps("hyperevm", [
89
154
  r("prjx", "Project X", "0x1EbDFC75FfE3ba3de61E7138a3E8706aC841Af9B", "v3-router", "MEDIUM–HIGH"),
90
155
  r("nest", "nest (CL)", "0xaA26B8e5Cadd04430c32787eCC3AA325e99681e9", "algebra", "HIGH"),
91
156
  r("ramses-ur", "Ramses CL V2", "0xc43b33b5DF826A48DAE764817647824ED4f476a7", "uniswap-ur", "MEDIUM", false, true),
92
157
  r("hyperswap", "HyperSwap V3", "0x6D99e7f6747AF2cDbB5164b6DD50e40D4fDe1e77", "v3-router02", "HIGH", true),
93
- ],
158
+ ]),
94
159
  notes: ["⚠ Small blocks cap a transaction at 3M gas: a buy that graduates a launch may need a big block."],
95
160
  },
96
161
  robinhood: {
97
162
  wrappedNative: strict("0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73"),
98
- zapRouters: [
163
+ zapRouters: withBookedZaps("robinhood", [
99
164
  r(UNISWAP_UR, "Uniswap v2/v3/v4 (+ Fables v4 pools)", "0x8876789976dEcBfCbBbe364623C63652db8C0904", "uniswap-ur", "HIGH"),
100
165
  r("ramses-ur", "Ramses", "0xbFbb2BCBc9dfFA029C27A249ae9BE031E1d83b1C", "uniswap-ur", "HIGH", true, true),
101
- ],
166
+ ]),
102
167
  notes: [],
103
168
  },
104
169
  arc: {
105
170
  wrappedNative: null,
106
- zapRouters: [r(UNISWAP_UR, "Uniswap v4 (native-USDC pools)", "0x4fcA4a51Ab4F23A7447b3284fBd7D73289A89Fb1", "uniswap-ur", "HIGH")],
171
+ zapRouters: withBookedZaps("arc", [r(UNISWAP_UR, "Uniswap v4 (native-USDC pools)", "0x4fcA4a51Ab4F23A7447b3284fBd7D73289A89Fb1", "uniswap-ur", "HIGH")]),
107
172
  notes: [
108
173
  "⚠ The native coin is USDC (18 dp at the EVM level; its ERC-20 view 0x3600000000000000000000000000000000000000 has 6 dp and no deposit()).",
109
174
  "⚠ No WETH9: WRAP_ETH does not apply; only v4 pools in address(0) take the native coin. The zap is for third-token quotes only.",
110
175
  ],
111
176
  },
177
+ elysium: {
178
+
179
+ wrappedNative: strict("0xbA876237B0F021A6c6D852d6c26E107997cC5E81"),
180
+
181
+ zapRouters: withBookedZaps("elysium", [r(UNISWAP_UR, "Uniswap v4 (native HYPE / USDC pools)", "0xA13f7611115752DEB2B13813BDDE16A5073e4b45", "uniswap-ur", "HIGH")]),
182
+ notes: [
183
+ "⚠ Arbitrum Orbit on HyperEVM: in a contract block.number is HyperEVM's block; the receipt's block is Elysium's.",
184
+ "⚠ Depth is Uniswap v4 only (native HYPE / USDC pools, no hooks): route the zap through V4_SWAP (route.v4), never WRAP_ETH; the v3 and V2 pools hold no depth.",
185
+ ],
186
+ },
112
187
  };
113
188
 
114
189
  export const EVM_CHAINS: Record<ChainKey, EvmChain> = Object.fromEntries(
115
190
  CHAIN_REGISTRY.flatMap((c) => (c.family === "evm" ? [[c.slug, { key: c.slug, chainId: c.chainId, name: c.label, nativeSymbol: c.native.symbol, ...ROUTES[c.slug], ...((c.v2DayOne as boolean) === false ? { v2DayOne: false as const } : {}) }]] : [])),
116
191
  ) as Record<ChainKey, EvmChain>;
117
192
 
193
+ export const FLOOR_ROUTER_ADDRESSES: Readonly<Record<ChainKey, Readonly<Record<string, string>>>> = Object.freeze(
194
+ Object.fromEntries(Object.values(EVM_CHAINS).map((c) => [c.key, Object.freeze(Object.fromEntries(c.zapRouters.map((r) => [r.slot, r.floorRouter])))])),
195
+ ) as Readonly<Record<ChainKey, Readonly<Record<string, string>>>>;
196
+
118
197
  export const v2DayOneChains = (): EvmChain[] => Object.values(EVM_CHAINS).filter((c) => c.v2DayOne !== false);
119
198
  export const chainById = (chainId: number): EvmChain | null => Object.values(EVM_CHAINS).find((c) => c.chainId === chainId) ?? null;
120
199
 
@@ -133,7 +212,7 @@ export const FLOOR_SALTS = {
133
212
  export const FLOOR_AMM_ADDRESS: string | null = "0xF10000bd05c2C01793C6d55F027346469683d225";
134
213
 
135
214
  export const FLOOR_AMM_FROM_BLOCK: Readonly<Record<ChainKey, number | null>> = {
136
- ethereum: 26327910, base: 53421827, bsc: 131270813, arbitrum: 520655168, arc: 29205598, robinhood: 104455459, hyperevm: 50398055,
215
+ ethereum: 26327910, base: 53421827, bsc: 131270813, arbitrum: 520655168, arc: 29205598, robinhood: 104455459, hyperevm: 50398055, elysium: 6058368,
137
216
  };
138
217
 
139
218
  const cat = (...h: string[]): string => "0x" + h.map((x) => bytesToHex(hexToBytes(x)).slice(2)).join("");
@@ -51,7 +51,7 @@ export const FLOOR_AMM_ABI = [
51
51
  {"type":"error","name":"UnknownClaimType","inputs":[]},
52
52
  {"type":"error","name":"UnknownLaunch","inputs":[]},
53
53
  {"type":"event","name":"ClaimSkipped","inputs":[{"name":"wallet","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"amount","type":"uint256","indexed":false}],"anonymous":false},
54
- {"type":"event","name":"Claimed","inputs":[{"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}],"anonymous":false},
54
+ {"type":"event","name":"Claimed","inputs":[{"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}],"anonymous":false},
55
55
  {"type":"event","name":"ConfigWritten","inputs":[{"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}],"anonymous":false},
56
56
  {"type":"event","name":"CreatorBuyUnlocked","inputs":[{"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}],"anonymous":false},
57
57
  {"type":"event","name":"Graduated","inputs":[{"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}],"anonymous":false},
@@ -3,6 +3,7 @@
3
3
  import { checksumAddress } from "../abi.ts";
4
4
  import { decodeEventLog, itemTopic } from "../items.ts";
5
5
  import type { EventArgsOf, EventName, Log } from "../items.ts";
6
+ import { LEGACY_CLAIMED_TOPIC, LEGACY_EVENTS, normalizeLegacyClaimed } from "./legacy-events.ts";
6
7
  import { FLOOR_AMM_ABI, FLOOR_AMM_UNFROZEN_EVENTS, FLOOR_ZAP_ABI } from "./iface.ts";
7
8
 
8
9
  export type FloorEventName = EventName<typeof FLOOR_AMM_ABI> | EventName<typeof FLOOR_ZAP_ABI>;
@@ -15,6 +16,8 @@ export interface FloorEvmEvent {
15
16
  address?: string;
16
17
 
17
18
  unfrozen?: true;
19
+
20
+ legacy?: true;
18
21
  }
19
22
 
20
23
  const ALL = [...FLOOR_AMM_ABI, ...FLOOR_ZAP_ABI, ...FLOOR_AMM_UNFROZEN_EVENTS];
@@ -38,10 +41,17 @@ for (const i of ALL.filter((i) => i.type === "event").reverse()) {
38
41
  });
39
42
  }
40
43
 
44
+ export const FLOOR_LEGACY_EVENT_TOPICS: Record<string, string> = { Claimed: LEGACY_CLAIMED_TOPIC };
45
+
41
46
  export function decodeFloorLog(log: Log, from?: readonly string[]): FloorEvmEvent | null {
42
47
  if (from && (!log.address || !from.some((a) => a.toLowerCase() === log.address!.toLowerCase()))) return null;
43
48
  const d: FloorEvmEvent | null = decodeEventLog(ALL, log);
44
- if (!d) return null;
49
+ if (!d) {
50
+ const old = decodeEventLog(LEGACY_EVENTS, log);
51
+ if (!old) return null;
52
+ const e: FloorEvmEvent = { ...old, args: normalizeLegacyClaimed(old.args), legacy: true };
53
+ return log.address ? { ...e, address: checksumAddress(log.address) } : e;
54
+ }
45
55
  if (UNFROZEN().has((log.topics[0] ?? "").toLowerCase())) d.unfrozen = true;
46
56
  return log.address ? { ...d, address: checksumAddress(log.address) } : d;
47
57
  }
@@ -0,0 +1,27 @@
1
+
2
+
3
+ import type { AbiItem } from "../items.ts";
4
+
5
+ export const LEGACY_CLAIMED_SIGNATURE =
6
+ "Claimed(address,address,address,uint8,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
7
+ export const LEGACY_CLAIMED_TOPIC = "0x586c69c7198e9e5c48c058d0267bd1388a73f9a8878aeb9d72d25331acc39aeb";
8
+
9
+ export const LEGACY_EVENTS: readonly AbiItem[] = [
10
+ {
11
+ type: "event", name: "Claimed", anonymous: false, inputs: [
12
+ { name: "wallet", type: "address", indexed: true }, { name: "sender", type: "address", indexed: true },
13
+ { name: "quote", type: "address", indexed: true }, { name: "types", type: "uint8", indexed: false },
14
+ { name: "creator", type: "uint256", indexed: false }, { name: "creatorRef", type: "uint256", indexed: false },
15
+ { name: "teamSlot", type: "uint256", indexed: false }, { name: "traderRef", type: "uint256", indexed: false },
16
+ { name: "holder", type: "uint256", indexed: false }, { name: "extra", type: "uint256", indexed: false },
17
+ { name: "amount", type: "uint256", indexed: false },
18
+ ],
19
+ },
20
+ ];
21
+
22
+ export const CLAIM_HOLDER_BIT = 512n;
23
+
24
+ export function normalizeLegacyClaimed(args: Record<string, any>): Record<string, any> {
25
+ const types = BigInt(args.types);
26
+ return { ...args, types: BigInt(args.holder) > 0n ? types | CLAIM_HOLDER_BIT : types };
27
+ }
package/src/evm/router.ts CHANGED
@@ -3,7 +3,8 @@
3
3
  import { encodeFunctionData } from "./items.ts";
4
4
  import { deadlineArg } from "./floor/calls.ts";
5
5
  import { EVM_NATIVE, NoRouteError, coinKey } from "../route/graph.ts";
6
- import { chainById } from "./chains.ts";
6
+ import { EVM_CHAINS, chainById } from "./chains.ts";
7
+ import type { ChainKey } from "./chains.ts";
7
8
  import type { Pool } from "../route/graph.ts";
8
9
  import type { HopQuote, RouteQuote } from "../route/quote.ts";
9
10
 
@@ -207,3 +208,27 @@ export function evmRouteCall(q: RouteQuote, p: { router: string; to: string; dea
207
208
  const b: RouterBuy = { path: ids(buys), tokenIn: s.tokenOut, amountIn: 0n, swapData: "0x", minQuoteIn: 0n, minTokensOut: mins(buys), to: p.to, deadline: p.deadline };
208
209
  return call(encodeRouterSwap(s, b, p.chainId), 0n);
209
210
  }
211
+
212
+ export async function floorRouterLive(rpc: { getCode: (address: string) => Promise<string | undefined> }, at: string | { chain: ChainKey; slot: string }): Promise<boolean> {
213
+ const address = floorRouterAt(at);
214
+ const code: unknown = await rpc.getCode(address);
215
+ if (code === undefined) return false;
216
+ if (typeof code !== "string" || !/^0x([0-9a-fA-F]{2})*$/.test(code)) throw new TypeError(`getCode(${address}) returned ${String(code)}, not hex bytes`);
217
+ return code.length > 2;
218
+ }
219
+
220
+ export async function assertFloorRouterLive(rpc: { getCode: (address: string) => Promise<string | undefined> }, at: string | { chain: ChainKey; slot: string }): Promise<string> {
221
+ const address = floorRouterAt(at);
222
+ if (!(await floorRouterLive(rpc, address))) throw new RangeError(`FloorRouter ${address} has no code on this chain yet: it is derived ahead of its deploy; do not send to it (a native coin sent to it is lost)`);
223
+ return address;
224
+ }
225
+
226
+ function floorRouterAt(at: string | { chain: ChainKey; slot: string }): string {
227
+ if (typeof at === "string") {
228
+ if (!/^0x[0-9a-fA-F]{40}$/.test(at)) throw new RangeError(`a FloorRouter is a 20-byte address: ${at}`);
229
+ return at;
230
+ }
231
+ const row = EVM_CHAINS[at.chain]?.zapRouters.find((r) => r.slot === at.slot);
232
+ if (row === undefined) throw new RangeError(`no FloorRouter slot ${at.slot} on ${at.chain}`);
233
+ return row.floorRouter;
234
+ }
package/src/evm/squid.ts CHANGED
@@ -96,19 +96,19 @@ export function buyHookErc20(p: Common & { quote: string; minTokensOut: bigint }
96
96
  };
97
97
  }
98
98
 
99
- export function buyHookNative(p: Common & { zap: string; swapData: string; minQuoteIn: bigint; minTokensOut: bigint }): SquidHook {
99
+ export function buyHookNative(p: Common & { zap: string; swapData: string; minQuoteIn: bigint; minTokensOut: bigint; quote?: string }): SquidHook {
100
100
  checkCommon(p);
101
101
  const user = checkUser(p);
102
102
  if (p.minQuoteIn <= 0n || p.minTokensOut <= 0n) throw new SquidHookError("NO_MINIMUM", "minQuoteIn and minTokensOut must be > 0");
103
103
  const zap = lc(p.zap, "zap");
104
- return {
105
- provider: "FLOOR",
106
- description: "Buy a FLOOR launch token with the native coin",
107
- calls: [
108
- call(SQUID_CALL.FullNativeBalance, zap, 0n, bytesToHex(encodeCall("buyWithEth(uint256,bytes,uint256,uint256,address,uint256)", [p.launchId, p.swapData, p.minQuoteIn, p.minTokensOut, user, p.deadline])), "0x", SQUID_GAS.zapBuy),
109
- call(SQUID_CALL.FullNativeBalance, user, 0n, "0x", "0x", SQUID_GAS.passOn),
110
- ],
111
- };
104
+ const quote = lc(p.quote ?? ZERO, "quote");
105
+ const calls = [
106
+ call(SQUID_CALL.FullNativeBalance, zap, 0n, bytesToHex(encodeCall("buyWithEth(uint256,bytes,uint256,uint256,address,uint256)", [p.launchId, p.swapData, p.minQuoteIn, p.minTokensOut, user, p.deadline])), "0x", SQUID_GAS.zapBuy),
107
+ call(SQUID_CALL.FullNativeBalance, user, 0n, "0x", "0x", SQUID_GAS.passOn),
108
+ ];
109
+
110
+ if (quote !== ZERO) calls.push(call(SQUID_CALL.FullTokenBalance, quote, 0n, bytesToHex(encodeCall("transfer(address,uint256)", [user, SQUID_FULL])), bytesToHex(encodeAbi(["address", "uint256"], [quote, 1n])), SQUID_GAS.transfer));
111
+ return { provider: "FLOOR", description: "Buy a FLOOR launch token with the native coin", calls };
112
112
  }
113
113
 
114
114
  export function sellHook(p: Common & { token: string; tokensIn: bigint; minQuoteOut: bigint; proceedsTo?: string }): SquidHook {