@floorlaunchpad/sdk 0.1.1 → 0.3.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 (292) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/LICENSE +201 -60
  3. package/README.md +45 -24
  4. package/dist/abi/evm-event-names.js +12 -0
  5. package/dist/abi/evm.gen.js +130 -0
  6. package/dist/abi/functions.gen.js +144 -0
  7. package/dist/abi/index.js +17 -0
  8. package/dist/abi/solana.gen.js +128 -0
  9. package/dist/burn.js +21 -0
  10. package/dist/client/evm/index.js +191 -0
  11. package/dist/client/index.js +19 -0
  12. package/dist/client/solana/index.js +259 -0
  13. package/dist/client/types.js +5 -0
  14. package/dist/codec.js +77 -0
  15. package/dist/config/codeHash.js +9 -0
  16. package/dist/config/generated.js +746 -0
  17. package/dist/config/index.js +49 -0
  18. package/dist/config/registry.gen.js +118 -0
  19. package/dist/config/solana-genesis.js +7 -0
  20. package/dist/ed25519.js +31 -0
  21. package/dist/errors.js +249 -0
  22. package/dist/events/index.js +40 -0
  23. package/dist/events/types.gen.js +3 -0
  24. package/dist/evm/abi.js +283 -0
  25. package/dist/evm/balances.js +26 -0
  26. package/dist/evm/chains.js +144 -0
  27. package/dist/evm/floor/abi.gen.js +195 -0
  28. package/dist/evm/floor/calls.js +230 -0
  29. package/dist/evm/floor/create.js +49 -0
  30. package/dist/evm/floor/events.js +41 -0
  31. package/dist/evm/floor/iface.js +44 -0
  32. package/dist/evm/items.js +209 -0
  33. package/dist/evm/keccak.js +118 -0
  34. package/dist/evm/multicall.js +30 -0
  35. package/dist/evm/router.js +184 -0
  36. package/dist/evm/zap.js +128 -0
  37. package/dist/fixtures.js +53 -0
  38. package/dist/generated/index.js +28 -0
  39. package/dist/generated/interface.gen.js +146 -0
  40. package/dist/handle.js +22 -0
  41. package/dist/index.js +91 -7
  42. package/dist/indexer/bodies.js +473 -0
  43. package/dist/indexer/client.js +104 -0
  44. package/dist/indexer/contract.js +349 -0
  45. package/dist/indexer/decode.js +97 -0
  46. package/dist/indexer/partners.js +100 -0
  47. package/dist/indexer/paths.js +127 -0
  48. package/dist/indexer/read.js +109 -0
  49. package/dist/indexer/stream.js +71 -0
  50. package/dist/lock.js +16 -0
  51. package/dist/math/fixed.js +154 -0
  52. package/dist/math/genesis.js +39 -0
  53. package/dist/math/index.js +20 -0
  54. package/dist/math/u256.js +49 -0
  55. package/dist/math/v2/ask.js +162 -0
  56. package/dist/math/v2/book.js +607 -0
  57. package/dist/math/v2/circulating.js +62 -0
  58. package/dist/math/v2/create.js +122 -0
  59. package/dist/math/v2/display.js +208 -0
  60. package/dist/math/v2/error.js +17 -0
  61. package/dist/math/v2/feasibility.js +174 -0
  62. package/dist/math/v2/fees.js +121 -0
  63. package/dist/math/v2/holders.js +105 -0
  64. package/dist/math/v2/milestones.js +40 -0
  65. package/dist/math/v2/pow.js +69 -0
  66. package/dist/math/v2/preset.js +151 -0
  67. package/dist/math/v2/receipt.js +108 -0
  68. package/dist/math/v2/relay.js +217 -0
  69. package/dist/math/v2/rows.js +365 -0
  70. package/dist/math/v2/split.js +111 -0
  71. package/dist/math/v2/sqrt.js +84 -0
  72. package/dist/math/v2/supply.js +21 -0
  73. package/dist/math/v2/team.js +75 -0
  74. package/dist/math/v2/trade.js +126 -0
  75. package/dist/math/v2/wide.js +51 -0
  76. package/dist/quote.js +6 -0
  77. package/dist/registryPrice.js +23 -0
  78. package/dist/route/edge-jupiter.js +42 -0
  79. package/dist/route/edge.js +11 -0
  80. package/dist/route/graph.js +51 -0
  81. package/dist/route/path.js +75 -0
  82. package/dist/route/quote.js +15 -0
  83. package/dist/route-jupiter.js +35 -0
  84. package/dist/route.js +8 -0
  85. package/dist/sha256.js +61 -0
  86. package/dist/solana/alt.js +18 -0
  87. package/dist/solana/floor/accounts.js +390 -0
  88. package/dist/solana/floor/borsh.js +66 -0
  89. package/dist/solana/floor/create.js +65 -0
  90. package/dist/solana/floor/events.js +140 -0
  91. package/dist/solana/floor/genesis.js +91 -0
  92. package/dist/solana/floor/genesisList.js +68 -0
  93. package/dist/solana/floor/instructions.js +435 -0
  94. package/dist/solana/floor/metadata.js +198 -0
  95. package/dist/solana/floor/mint.js +206 -0
  96. package/dist/solana/floor/program.js +64 -0
  97. package/dist/solana/floor/registry.js +83 -0
  98. package/dist/solana/instruction.js +49 -0
  99. package/dist/solana/pda.js +88 -0
  100. package/dist/solana/tx.js +138 -0
  101. package/dist/v2/burnPreview.js +35 -0
  102. package/dist/v2/circulating.js +11 -0
  103. package/dist/v2/claimAllEvm.js +70 -0
  104. package/dist/v2/claims-evm.js +120 -0
  105. package/dist/v2/claims.js +218 -0
  106. package/dist/v2/dead.js +21 -0
  107. package/dist/v2/devbuy.js +37 -0
  108. package/dist/v2/events.js +115 -0
  109. package/dist/v2/evm.js +299 -0
  110. package/dist/v2/evmReads.js +76 -0
  111. package/dist/v2/genesis.js +76 -0
  112. package/dist/v2/layouts.js +217 -0
  113. package/dist/v2/market-evm.js +74 -0
  114. package/dist/v2/presetRowEvm.js +45 -0
  115. package/dist/v2/press.js +106 -0
  116. package/dist/v2/quoteMint.js +52 -0
  117. package/dist/v2/receipt-tx.js +149 -0
  118. package/dist/v2/route-alt.js +114 -0
  119. package/dist/v2/route.js +389 -0
  120. package/dist/v2/solana.js +391 -0
  121. package/dist/v2/solanaSettle.js +97 -0
  122. package/dist/v2/tx/evm.js +126 -0
  123. package/dist/v2/tx/genesis.js +47 -0
  124. package/dist/v2/tx/index.js +5 -0
  125. package/dist/v2/tx/solana.js +118 -0
  126. package/dist/v2/types.js +13 -0
  127. package/docs/aggregator.md +61 -0
  128. package/docs/bot.md +50 -0
  129. package/docs/frontend.md +29 -0
  130. package/docs/wallet.md +54 -0
  131. package/package.json +428 -32
  132. package/src/abi/evm-event-names.ts +12 -0
  133. package/src/abi/evm.gen.ts +139 -0
  134. package/src/abi/functions.gen.ts +154 -0
  135. package/src/abi/index.ts +30 -0
  136. package/src/abi/solana.gen.ts +138 -0
  137. package/src/burn.ts +37 -0
  138. package/src/client/evm/index.ts +199 -0
  139. package/src/client/index.ts +23 -0
  140. package/src/client/solana/index.ts +260 -0
  141. package/src/client/types.ts +162 -0
  142. package/src/codec.ts +77 -0
  143. package/src/config/codeHash.ts +9 -0
  144. package/src/config/generated.ts +746 -0
  145. package/src/config/index.ts +91 -0
  146. package/src/config/registry.gen.ts +118 -0
  147. package/src/config/solana-genesis.ts +7 -0
  148. package/src/ed25519.ts +31 -0
  149. package/src/errors.ts +270 -0
  150. package/src/events/index.ts +44 -0
  151. package/src/events/types.gen.ts +831 -0
  152. package/src/evm/abi.ts +292 -0
  153. package/src/evm/balances.ts +26 -0
  154. package/src/evm/chains.ts +167 -0
  155. package/src/evm/floor/abi.gen.ts +195 -0
  156. package/src/evm/floor/calls.ts +247 -0
  157. package/src/evm/floor/create.ts +68 -0
  158. package/src/evm/floor/events.ts +51 -0
  159. package/src/evm/floor/iface.ts +45 -0
  160. package/src/evm/items.ts +252 -0
  161. package/src/evm/keccak.ts +118 -0
  162. package/src/evm/multicall.ts +43 -0
  163. package/src/evm/router.ts +209 -0
  164. package/src/evm/zap.ts +152 -0
  165. package/src/fixtures.ts +53 -0
  166. package/src/generated/index.ts +29 -0
  167. package/src/generated/interface.gen.ts +153 -0
  168. package/src/handle.ts +22 -0
  169. package/src/index.ts +91 -6
  170. package/src/indexer/bodies.ts +528 -0
  171. package/src/indexer/client.ts +178 -0
  172. package/src/indexer/contract.ts +410 -0
  173. package/src/indexer/decode.ts +109 -0
  174. package/src/indexer/partners.ts +109 -0
  175. package/src/indexer/paths.ts +190 -0
  176. package/src/indexer/read.ts +119 -0
  177. package/src/indexer/stream.ts +83 -0
  178. package/src/lock.ts +16 -0
  179. package/src/math/fixed.ts +154 -0
  180. package/src/math/genesis.ts +39 -0
  181. package/src/math/index.ts +24 -0
  182. package/src/math/u256.ts +49 -0
  183. package/src/math/v2/ask.ts +218 -0
  184. package/src/math/v2/book.ts +660 -0
  185. package/src/math/v2/circulating.ts +69 -0
  186. package/src/math/v2/create.ts +139 -0
  187. package/src/math/v2/display.ts +250 -0
  188. package/src/math/v2/error.ts +19 -0
  189. package/src/math/v2/feasibility.ts +200 -0
  190. package/src/math/v2/fees.ts +121 -0
  191. package/src/math/v2/holders.ts +124 -0
  192. package/src/math/v2/milestones.ts +51 -0
  193. package/src/math/v2/pow.ts +71 -0
  194. package/src/math/v2/preset.ts +189 -0
  195. package/src/math/v2/receipt.ts +162 -0
  196. package/src/math/v2/relay.ts +235 -0
  197. package/src/math/v2/rows.ts +412 -0
  198. package/src/math/v2/split.ts +160 -0
  199. package/src/math/v2/sqrt.ts +86 -0
  200. package/src/math/v2/supply.ts +27 -0
  201. package/src/math/v2/team.ts +75 -0
  202. package/src/math/v2/trade.ts +145 -0
  203. package/src/math/v2/wide.ts +52 -0
  204. package/src/quote.ts +6 -0
  205. package/src/registryPrice.ts +28 -0
  206. package/src/route/edge-jupiter.ts +71 -0
  207. package/src/route/edge.ts +22 -0
  208. package/src/route/graph.ts +77 -0
  209. package/src/route/path.ts +84 -0
  210. package/src/route/quote.ts +46 -0
  211. package/src/route-jupiter.ts +36 -0
  212. package/src/route.ts +8 -0
  213. package/src/sha256.ts +61 -0
  214. package/src/solana/alt.ts +25 -0
  215. package/src/solana/floor/accounts.ts +393 -0
  216. package/src/solana/floor/borsh.ts +66 -0
  217. package/src/solana/floor/create.ts +89 -0
  218. package/src/solana/floor/events.ts +147 -0
  219. package/src/solana/floor/genesis.ts +111 -0
  220. package/src/solana/floor/genesisList.ts +75 -0
  221. package/src/solana/floor/instructions.ts +491 -0
  222. package/src/solana/floor/metadata.ts +246 -0
  223. package/src/solana/floor/mint.ts +242 -0
  224. package/src/solana/floor/program.ts +64 -0
  225. package/src/solana/floor/registry.ts +96 -0
  226. package/src/solana/instruction.ts +61 -0
  227. package/src/solana/pda.ts +91 -0
  228. package/src/solana/tx.ts +143 -0
  229. package/src/v2/burnPreview.ts +52 -0
  230. package/src/v2/circulating.ts +22 -0
  231. package/src/v2/claimAllEvm.ts +97 -0
  232. package/src/v2/claims-evm.ts +179 -0
  233. package/src/v2/claims.ts +288 -0
  234. package/src/v2/dead.ts +21 -0
  235. package/src/v2/devbuy.ts +55 -0
  236. package/src/v2/events.ts +131 -0
  237. package/src/v2/evm.ts +349 -0
  238. package/src/v2/evmReads.ts +121 -0
  239. package/src/v2/genesis.ts +80 -0
  240. package/src/v2/layouts.ts +219 -0
  241. package/src/v2/market-evm.ts +95 -0
  242. package/src/v2/presetRowEvm.ts +54 -0
  243. package/src/v2/press.ts +124 -0
  244. package/src/v2/quoteMint.ts +63 -0
  245. package/src/v2/receipt-tx.ts +251 -0
  246. package/src/v2/route-alt.ts +114 -0
  247. package/src/v2/route.ts +494 -0
  248. package/src/v2/solana.ts +439 -0
  249. package/src/v2/solanaSettle.ts +117 -0
  250. package/src/v2/tx/evm.ts +152 -0
  251. package/src/v2/tx/genesis.ts +66 -0
  252. package/src/v2/tx/index.ts +5 -0
  253. package/src/v2/tx/solana.ts +140 -0
  254. package/src/v2/types.ts +284 -0
  255. package/dist/adapter.d.ts +0 -28
  256. package/dist/adapter.d.ts.map +0 -1
  257. package/dist/adapter.js +0 -2
  258. package/dist/adapter.js.map +0 -1
  259. package/dist/chain.d.ts +0 -23
  260. package/dist/chain.d.ts.map +0 -1
  261. package/dist/chain.js +0 -25
  262. package/dist/chain.js.map +0 -1
  263. package/dist/client.d.ts +0 -26
  264. package/dist/client.d.ts.map +0 -1
  265. package/dist/client.js +0 -43
  266. package/dist/client.js.map +0 -1
  267. package/dist/dex-adapter.d.ts +0 -228
  268. package/dist/dex-adapter.d.ts.map +0 -1
  269. package/dist/dex-adapter.js +0 -407
  270. package/dist/dex-adapter.js.map +0 -1
  271. package/dist/index.d.ts +0 -7
  272. package/dist/index.d.ts.map +0 -1
  273. package/dist/index.js.map +0 -1
  274. package/dist/quotes.d.ts +0 -12
  275. package/dist/quotes.d.ts.map +0 -1
  276. package/dist/quotes.gen.d.ts +0 -8
  277. package/dist/quotes.gen.d.ts.map +0 -1
  278. package/dist/quotes.gen.js +0 -2170
  279. package/dist/quotes.gen.js.map +0 -1
  280. package/dist/quotes.js +0 -24
  281. package/dist/quotes.js.map +0 -1
  282. package/dist/types.d.ts +0 -111
  283. package/dist/types.d.ts.map +0 -1
  284. package/dist/types.js +0 -2
  285. package/dist/types.js.map +0 -1
  286. package/src/adapter.ts +0 -20
  287. package/src/chain.ts +0 -39
  288. package/src/client.ts +0 -41
  289. package/src/dex-adapter.ts +0 -477
  290. package/src/quotes.gen.ts +0 -2170
  291. package/src/quotes.ts +0 -29
  292. package/src/types.ts +0 -115
@@ -0,0 +1,209 @@
1
+
2
+
3
+ import { encodeFunctionData } from "./items.ts";
4
+ import { deadlineArg } from "./floor/calls.ts";
5
+ import { EVM_NATIVE, NoRouteError, coinKey } from "../route/graph.ts";
6
+ import { chainById } from "./chains.ts";
7
+ import type { Pool } from "../route/graph.ts";
8
+ import type { HopQuote, RouteQuote } from "../route/quote.ts";
9
+
10
+ const BUY = [
11
+ { name: "path", type: "uint256[]" },
12
+ { name: "tokenIn", type: "address" },
13
+ { name: "amountIn", type: "uint256" },
14
+ { name: "swapData", type: "bytes" },
15
+ { name: "minQuoteIn", type: "uint256" },
16
+ { name: "minTokensOut", type: "uint256[]" },
17
+ { name: "to", type: "address" },
18
+ { name: "deadline", type: "uint256" },
19
+ ] as const;
20
+
21
+ const SELL = [
22
+ { name: "path", type: "uint256[]" },
23
+ { name: "tokensIn", type: "uint256" },
24
+ { name: "minQuoteOut", type: "uint256[]" },
25
+ { name: "tokenOut", type: "address" },
26
+ { name: "swapIn", type: "uint256" },
27
+ { name: "swapData", type: "bytes" },
28
+ { name: "minOut", type: "uint256" },
29
+ { name: "to", type: "address" },
30
+ { name: "deadline", type: "uint256" },
31
+ ] as const;
32
+ const buyArg = (name: string) => ({ name, type: "tuple", internalType: "struct IFloorRouter.Buy", components: BUY }) as const;
33
+ const sellArg = (name: string) => ({ name, type: "tuple", internalType: "struct IFloorRouter.Sell", components: SELL }) as const;
34
+ const err = (name: string, inputs: readonly { name: string; type: string }[] = []) => ({ type: "error", name, inputs }) as const;
35
+ const SELL_OUT = [{ name: "amountOut", type: "uint256" }, { name: "quoteOut", type: "uint256" }] as const;
36
+
37
+ export const FLOOR_ROUTER_ABI = [
38
+ { type: "function", name: "floorAmm", inputs: [], outputs: [{ name: "", type: "address", internalType: "contract IFloorAmm" }], stateMutability: "view" },
39
+ { type: "function", name: "router", inputs: [], outputs: [{ name: "", type: "address" }], stateMutability: "view" },
40
+ { type: "function", name: "sell", inputs: [sellArg("s")], outputs: SELL_OUT, stateMutability: "nonpayable" },
41
+ {
42
+ type: "function",
43
+ name: "sellWithPermit",
44
+ inputs: [sellArg("s"), { name: "permitDeadline", type: "uint256" }, { name: "v", type: "uint8" }, { name: "r", type: "bytes32" }, { name: "ss", type: "bytes32" }],
45
+ outputs: SELL_OUT,
46
+ stateMutability: "nonpayable",
47
+ },
48
+ {
49
+ type: "event",
50
+ name: "Sold",
51
+ anonymous: false,
52
+ inputs: [
53
+ { name: "sender", type: "address", indexed: true },
54
+ { name: "to", type: "address", indexed: true },
55
+ { name: "launchId", type: "uint256", indexed: true },
56
+ { name: "tokensIn", type: "uint256", indexed: false },
57
+ { name: "hops", type: "uint256", indexed: false },
58
+ { name: "tokenOut", type: "address", indexed: false },
59
+ { name: "quoteOut", type: "uint256", indexed: false },
60
+ { name: "amountOut", type: "uint256", indexed: false },
61
+ { name: "refundQuote", type: "uint256", indexed: false },
62
+ ],
63
+ },
64
+ {
65
+ type: "event",
66
+ name: "Bought",
67
+ anonymous: false,
68
+ inputs: [
69
+ { name: "sender", type: "address", indexed: true },
70
+ { name: "to", type: "address", indexed: true },
71
+ { name: "launchId", type: "uint256", indexed: true },
72
+ { name: "tokenIn", type: "address", indexed: false },
73
+ { name: "amountIn", type: "uint256", indexed: false },
74
+ { name: "hops", type: "uint256", indexed: false },
75
+ { name: "quoteIn", type: "uint256", indexed: false },
76
+ { name: "tokensOut", type: "uint256", indexed: false },
77
+ { name: "refundIn", type: "uint256", indexed: false },
78
+ ],
79
+ },
80
+ err("NotRouter"),
81
+ err("SwapFailed", [{ name: "reason", type: "bytes" }]),
82
+ err("SwapDataNotEmpty"),
83
+ err("BadPath"),
84
+ err("QuoteShort"),
85
+ err("SlippageExceeded"),
86
+ err("Expired"),
87
+ err("BadValue"),
88
+ err("Reentrancy"),
89
+
90
+ { type: "function", name: "buy", inputs: [buyArg("b")], outputs: [{ name: "tokensOut", type: "uint256" }, { name: "quoteIn", type: "uint256" }], stateMutability: "payable" },
91
+ { type: "function", name: "swap", inputs: [sellArg("s"), buyArg("b")], outputs: [{ name: "tokensOut", type: "uint256" }], stateMutability: "nonpayable" },
92
+ ] as const;
93
+
94
+ export const SWAP_IN_ALL = (1n << 256n) - 1n;
95
+
96
+ export interface RouterBuy {
97
+ path: bigint[];
98
+ tokenIn: string;
99
+ amountIn: bigint;
100
+ swapData: string;
101
+ minQuoteIn: bigint;
102
+ minTokensOut: bigint[];
103
+ to: string;
104
+ deadline: bigint;
105
+ }
106
+ export interface RouterSell {
107
+ path: bigint[];
108
+ tokensIn: bigint;
109
+ minQuoteOut: bigint[];
110
+ tokenOut: string;
111
+
112
+ swapIn: bigint;
113
+ swapData: string;
114
+ minOut: bigint;
115
+ to: string;
116
+ deadline: bigint;
117
+ }
118
+
119
+ export function checkFloorHops(chainId: unknown, floorHops: number): void {
120
+ if (typeof chainId !== "number" || !Number.isInteger(chainId)) throw new RangeError("an EVM route names its chainId");
121
+ const row = chainById(chainId);
122
+ if (row?.maxFloorHops !== undefined && floorHops > row.maxFloorHops) {
123
+ throw new NoRouteError("TooManyHops", `${floorHops} FLOOR trades: ${row.name} (chain ${row.chainId}) carries at most ${row.maxFloorHops} per route`);
124
+ }
125
+ }
126
+
127
+ const checkPath = (path: bigint[], mins: bigint[]): void => {
128
+ if (path.length === 0) throw new RangeError("BadPath: an empty path");
129
+ if (mins.length !== path.length) throw new RangeError("BadPath: one min-out a hop");
130
+ };
131
+
132
+ export function encodeRouterBuy(b: RouterBuy, chainId: number): string {
133
+ checkPath(b.path, b.minTokensOut);
134
+ checkFloorHops(chainId, b.path.length);
135
+ return encodeFunctionData(FLOOR_ROUTER_ABI, "buy", { b });
136
+ }
137
+
138
+ export function encodeRouterSell(s: RouterSell, chainId: number): string {
139
+ checkPath(s.path, s.minQuoteOut);
140
+ checkFloorHops(chainId, s.path.length);
141
+ if (s.tokensIn === 0n || coinKey(s.to) === EVM_NATIVE) throw new RangeError("BadValue: tokensIn > 0 and a recipient");
142
+ return encodeFunctionData(FLOOR_ROUTER_ABI, "sell", { s });
143
+ }
144
+
145
+ export function encodeRouterSellWithPermit(s: RouterSell, permit: { deadline: bigint; v: number; r: string; s: string }, chainId: number): string {
146
+ checkPath(s.path, s.minQuoteOut);
147
+ checkFloorHops(chainId, s.path.length);
148
+ if (s.tokensIn === 0n || coinKey(s.to) === EVM_NATIVE) throw new RangeError("BadValue: tokensIn > 0 and a recipient");
149
+ return encodeFunctionData(FLOOR_ROUTER_ABI, "sellWithPermit", { s, permitDeadline: permit.deadline, v: BigInt(permit.v), r: permit.r, ss: permit.s });
150
+ }
151
+
152
+ export function encodeRouterSwap(s: RouterSell, b: RouterBuy, chainId: number): string {
153
+ checkPath(s.path, s.minQuoteOut);
154
+ checkPath(b.path, b.minTokensOut);
155
+ checkFloorHops(chainId, s.path.length + b.path.length);
156
+ if (coinKey(b.tokenIn) !== coinKey(s.tokenOut) || b.amountIn !== 0n) throw new RangeError("BadPath: swap's buy takes the sell's output (b.tokenIn = s.tokenOut, b.amountIn = 0)");
157
+ return encodeFunctionData(FLOOR_ROUTER_ABI, "swap", { s, b });
158
+ }
159
+
160
+ const idOf = (pool: Pool): bigint => {
161
+ if (pool.launchId === undefined) throw new RangeError(`pool ${pool.symbol}: an EVM pool needs its launchId`);
162
+ return pool.launchId;
163
+ };
164
+
165
+ export function evmRouteCall(q: RouteQuote, p: { router: string; to: string; deadline: bigint; chainId: number; swapData?: string[] }): { to: string; data: string; value: bigint; gas?: bigint } {
166
+ if (q.path.chain !== "evm") throw new RangeError("evmRouteCall builds EVM routes; Solana routes are `routeInstructions`");
167
+ checkFloorHops(p.chainId, q.hops.filter((h) => h.hop.kind !== "edge").length);
168
+ deadlineArg(p.deadline);
169
+ const hs = q.hops;
170
+ const sells = hs.filter((h) => h.hop.kind === "sell");
171
+ const buys = hs.filter((h) => h.hop.kind === "buy");
172
+ const edges = hs.filter((h) => h.hop.kind === "edge");
173
+ if (edges.length > 1) throw new RangeError("BadPath: one edge leg a route");
174
+ const sd = p.swapData ?? [];
175
+ if (sd.length !== edges.length) throw new RangeError(`the route has ${edges.length} edge leg(s): pass ${edges.length} swapData`);
176
+ const edge = edges[0] as (HopQuote & { hop: { kind: "edge"; from: string; to: string } }) | undefined;
177
+ const pool = (h: HopQuote): Pool => (h.hop as { pool: Pool }).pool;
178
+ const ids = (xs: HopQuote[]): bigint[] => xs.map((h) => idOf(pool(h)));
179
+ const mins = (xs: HopQuote[]): bigint[] => xs.map((h) => h.minOut);
180
+ const gas = hs.every((h) => h.gas !== undefined) ? hs.reduce((n, h) => n + (h.gas as bigint), 0n) : undefined;
181
+ const call = (data: string, value: bigint) => ({ to: p.router, data, value, ...(gas !== undefined ? { gas } : {}) });
182
+
183
+ if (sells.length === 0) {
184
+
185
+ const base = pool(buys[0]).quote;
186
+ const tokenIn = edge ? edge.hop.from : base;
187
+ const native = coinKey(tokenIn) === EVM_NATIVE;
188
+ const r: RouterBuy = { path: ids(buys), tokenIn, amountIn: native ? 0n : q.amountIn, swapData: edge ? sd[0] : "0x", minQuoteIn: edge ? edge.minOut : 0n, minTokensOut: mins(buys), to: p.to, deadline: p.deadline };
189
+ return call(encodeRouterBuy(r, p.chainId), native ? q.amountIn : 0n);
190
+ }
191
+ const last = sells[sells.length - 1];
192
+
193
+ const s: RouterSell = {
194
+ path: ids(sells),
195
+ tokensIn: q.amountIn,
196
+ minQuoteOut: mins(sells),
197
+ tokenOut: edge ? edge.hop.to : pool(last).quote,
198
+
199
+ swapIn: edge ? edge.amountIn : 0n,
200
+ swapData: edge ? sd[0] : "0x",
201
+ minOut: edge ? edge.minOut : last.minOut,
202
+
203
+ to: buys.length ? EVM_NATIVE : p.to,
204
+ deadline: p.deadline,
205
+ };
206
+ if (buys.length === 0) return call(encodeRouterSell(s, p.chainId), 0n);
207
+ 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
+ return call(encodeRouterSwap(s, b, p.chainId), 0n);
209
+ }
package/src/evm/zap.ts ADDED
@@ -0,0 +1,152 @@
1
+
2
+
3
+ import { bytesToHex, checksumAddress, encodeAbi, hexToBytes } from "./abi.ts";
4
+ import { encodeFunctionData } from "./items.ts";
5
+
6
+ export type ZapFamily = "uniswap-ur" | "v3-router" | "v3-router02" | "algebra" | "v2-router" | "aerodrome-v2";
7
+
8
+ export const UR_V3_SWAP_EXACT_IN = 0x00;
9
+ export const UR_V2_SWAP_EXACT_IN = 0x08;
10
+ export const UR_WRAP_ETH = 0x0b;
11
+ export const UR_UNWRAP_WETH = 0x0c;
12
+ export const UR_SWEEP = 0x04;
13
+ export const UR_MSG_SENDER = "0x0000000000000000000000000000000000000001";
14
+ export const UR_ADDRESS_THIS = "0x0000000000000000000000000000000000000002";
15
+
16
+ export interface ZapRoute {
17
+
18
+ tokens: readonly string[];
19
+
20
+ fees?: readonly number[];
21
+
22
+ stable?: readonly boolean[];
23
+ factory?: string;
24
+ }
25
+
26
+ export interface ZapSwapParams {
27
+ family: ZapFamily;
28
+ route: ZapRoute;
29
+
30
+ amountIn: bigint;
31
+
32
+ minQuoteOut: bigint;
33
+
34
+ zap: string;
35
+ deadline: bigint;
36
+ }
37
+
38
+ const fn = (name: string, inputs: readonly { name: string; type: string; components?: any }[]) => ({ type: "function", name, inputs, outputs: [], stateMutability: "payable" }) as const;
39
+ const tup = (fields: [string, string][]) => fields.map(([name, type]) => ({ name, type }));
40
+
41
+ export function v3Path(tokens: readonly string[], fees: readonly number[]): string {
42
+ if (tokens.length < 2 || fees.length !== tokens.length - 1) throw new RangeError("a V3 path is n tokens and n − 1 fees");
43
+ let out = "0x";
44
+ tokens.forEach((t, i) => {
45
+ out += bytesToHex(hexToBytes(t)).slice(2);
46
+ if (i < fees.length) {
47
+ const f = fees[i];
48
+ if (!Number.isInteger(f) || f < 0 || f >= 1 << 24) throw new RangeError(`fee ${f} is not a uint24`);
49
+ out += f.toString(16).padStart(6, "0");
50
+ }
51
+ });
52
+ return out;
53
+ }
54
+
55
+ export function algebraPath(tokens: readonly string[]): string {
56
+ if (tokens.length < 2) throw new RangeError("a path is at least two tokens");
57
+ return "0x" + tokens.map((t) => bytesToHex(hexToBytes(t)).slice(2)).join("");
58
+ }
59
+
60
+ const checkRoute = (p: ZapSwapParams): void => {
61
+ if (p.amountIn <= 0n) throw new RangeError("amountIn must be > 0");
62
+ if (p.minQuoteOut <= 0n) throw new RangeError("minQuoteOut must be > 0 (the NO_MINIMUM rule)");
63
+ if (p.route.tokens.length < 2) throw new RangeError("a route is at least two tokens");
64
+ };
65
+
66
+ function universalRouter(p: ZapSwapParams): string {
67
+ const wrap = bytesToHex(encodeAbi(["address", "uint256"], [UR_ADDRESS_THIS, p.amountIn]));
68
+ let cmd: number;
69
+ let swap: string;
70
+ if (p.route.fees) {
71
+ cmd = UR_V3_SWAP_EXACT_IN;
72
+ swap = bytesToHex(encodeAbi(["address", "uint256", "uint256", "bytes", "bool", "uint256[]"], [UR_MSG_SENDER, p.amountIn, p.minQuoteOut, v3Path(p.route.tokens, p.route.fees), false, []]));
73
+ } else {
74
+ cmd = UR_V2_SWAP_EXACT_IN;
75
+ swap = bytesToHex(encodeAbi(["address", "uint256", "uint256", "address[]", "bool", "uint256[]"], [UR_MSG_SENDER, p.amountIn, p.minQuoteOut, [...p.route.tokens], false, []]));
76
+ }
77
+ const commands = "0x" + [UR_WRAP_ETH, cmd].map((c) => c.toString(16).padStart(2, "0")).join("");
78
+ const abi = [fn("execute", [{ name: "commands", type: "bytes" }, { name: "inputs", type: "bytes[]" }, { name: "deadline", type: "uint256" }])];
79
+ return encodeFunctionData(abi, "execute", { commands, inputs: [wrap, swap], deadline: p.deadline });
80
+ }
81
+
82
+ const REFUND_ETH = [fn("refundETH", [])];
83
+ const REFUND_NATIVE = [fn("refundNativeToken", [])];
84
+
85
+ function v3Router(p: ZapSwapParams, v02: boolean): string {
86
+ const fees = p.route.fees;
87
+ if (!fees) throw new RangeError("a V3 router route needs its fees");
88
+ const [tokenIn, tokenOut] = [p.route.tokens[0], p.route.tokens[p.route.tokens.length - 1]];
89
+ let swap: string;
90
+ if (p.route.tokens.length === 2) {
91
+ const fields: [string, string][] = v02
92
+ ? [["tokenIn", "address"], ["tokenOut", "address"], ["fee", "uint24"], ["recipient", "address"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"], ["sqrtPriceLimitX96", "uint160"]]
93
+ : [["tokenIn", "address"], ["tokenOut", "address"], ["fee", "uint24"], ["recipient", "address"], ["deadline", "uint256"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"], ["sqrtPriceLimitX96", "uint160"]];
94
+ const abi = [fn("exactInputSingle", [{ name: "params", type: "tuple", components: tup(fields) }])];
95
+ swap = encodeFunctionData(abi, "exactInputSingle", { params: { tokenIn, tokenOut, fee: BigInt(fees[0]), recipient: p.zap, deadline: p.deadline, amountIn: p.amountIn, amountOutMinimum: p.minQuoteOut, sqrtPriceLimitX96: 0n } });
96
+ } else {
97
+ const fields: [string, string][] = v02
98
+ ? [["path", "bytes"], ["recipient", "address"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"]]
99
+ : [["path", "bytes"], ["recipient", "address"], ["deadline", "uint256"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"]];
100
+ const abi = [fn("exactInput", [{ name: "params", type: "tuple", components: tup(fields) }])];
101
+ swap = encodeFunctionData(abi, "exactInput", { params: { path: v3Path(p.route.tokens, fees), recipient: p.zap, deadline: p.deadline, amountIn: p.amountIn, amountOutMinimum: p.minQuoteOut } });
102
+ }
103
+ const refund = encodeFunctionData(REFUND_ETH, "refundETH");
104
+ if (v02) return encodeFunctionData([fn("multicall", [{ name: "deadline", type: "uint256" }, { name: "data", type: "bytes[]" }])], "multicall", { deadline: p.deadline, data: [swap, refund] });
105
+ return encodeFunctionData([fn("multicall", [{ name: "data", type: "bytes[]" }])], "multicall", { data: [swap, refund] });
106
+ }
107
+
108
+ function algebra(p: ZapSwapParams): string {
109
+ const [tokenIn, tokenOut] = [p.route.tokens[0], p.route.tokens[p.route.tokens.length - 1]];
110
+ let swap: string;
111
+ if (p.route.tokens.length === 2) {
112
+ const fields: [string, string][] = [["tokenIn", "address"], ["tokenOut", "address"], ["recipient", "address"], ["deadline", "uint256"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"], ["limitSqrtPrice", "uint160"]];
113
+ swap = encodeFunctionData([fn("exactInputSingle", [{ name: "params", type: "tuple", components: tup(fields) }])], "exactInputSingle", { params: { tokenIn, tokenOut, recipient: p.zap, deadline: p.deadline, amountIn: p.amountIn, amountOutMinimum: p.minQuoteOut, limitSqrtPrice: 0n } });
114
+ } else {
115
+ const fields: [string, string][] = [["path", "bytes"], ["recipient", "address"], ["deadline", "uint256"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"]];
116
+ swap = encodeFunctionData([fn("exactInput", [{ name: "params", type: "tuple", components: tup(fields) }])], "exactInput", { params: { path: algebraPath(p.route.tokens), recipient: p.zap, deadline: p.deadline, amountIn: p.amountIn, amountOutMinimum: p.minQuoteOut } });
117
+ }
118
+ return encodeFunctionData([fn("multicall", [{ name: "data", type: "bytes[]" }])], "multicall", { data: [swap, encodeFunctionData(REFUND_NATIVE, "refundNativeToken")] });
119
+ }
120
+
121
+ function v2Router(p: ZapSwapParams): string {
122
+ const abi = [fn("swapExactETHForTokens", tup([["amountOutMin", "uint256"], ["path", "address[]"], ["to", "address"], ["deadline", "uint256"]]))];
123
+ return encodeFunctionData(abi, "swapExactETHForTokens", { amountOutMin: p.minQuoteOut, path: [...p.route.tokens], to: p.zap, deadline: p.deadline });
124
+ }
125
+
126
+ function aerodromeV2(p: ZapSwapParams): string {
127
+ const { tokens, stable, factory } = p.route;
128
+ if (!stable || stable.length !== tokens.length - 1 || !factory) throw new RangeError("an Aerodrome route needs a stable flag per hop and the factory");
129
+ const route = { name: "routes", type: "tuple[]", components: tup([["from", "address"], ["to", "address"], ["stable", "bool"], ["factory", "address"]]) };
130
+ const abi = [fn("swapExactETHForTokens", [{ name: "amountOutMin", type: "uint256" }, route, { name: "to", type: "address" }, { name: "deadline", type: "uint256" }])];
131
+ const routes = stable.map((s, i) => ({ from: tokens[i], to: tokens[i + 1], stable: s, factory }));
132
+ return encodeFunctionData(abi, "swapExactETHForTokens", { amountOutMin: p.minQuoteOut, routes, to: p.zap, deadline: p.deadline });
133
+ }
134
+
135
+ export function zapSwapData(p: ZapSwapParams): string {
136
+ checkRoute(p);
137
+ checksumAddress(p.zap);
138
+ switch (p.family) {
139
+ case "uniswap-ur":
140
+ return universalRouter(p);
141
+ case "v3-router":
142
+ return v3Router(p, false);
143
+ case "v3-router02":
144
+ return v3Router(p, true);
145
+ case "algebra":
146
+ return algebra(p);
147
+ case "v2-router":
148
+ return v2Router(p);
149
+ case "aerodrome-v2":
150
+ return aerodromeV2(p);
151
+ }
152
+ }
@@ -0,0 +1,53 @@
1
+
2
+
3
+ import { addressBytes, base58Encode } from "./codec.ts";
4
+ import { encodeAccount } from "./solana/floor/accounts.ts";
5
+ import { TOKEN_PROGRAM_ID } from "./solana/pda.ts";
6
+ import { encodeAccountV2 } from "./v2/layouts.ts";
7
+
8
+ export function fixtureAddress(i: number): string {
9
+ if (!Number.isInteger(i) || i < 0 || i > 0xffff) throw new RangeError(`fixture slot ${i}`);
10
+ const b = new Uint8Array(32);
11
+ b[0] = 0xf0;
12
+ b[1] = i & 0xff;
13
+ b[2] = i >> 8;
14
+ return base58Encode(b);
15
+ }
16
+
17
+ export function fixtureEvmAddress(i: number): string {
18
+ if (!Number.isInteger(i) || i < 0 || i > 0xffff) throw new RangeError(`fixture slot ${i}`);
19
+ return "0x" + "f0".padEnd(36, "0") + i.toString(16).padStart(4, "0");
20
+ }
21
+
22
+ export const fixtureKeys = () => ({
23
+ launch: fixtureAddress(1), creator: fixtureAddress(2), wallet: fixtureAddress(3), quoteMint: fixtureAddress(4), baseMint: fixtureAddress(5),
24
+ tokenVault: fixtureAddress(6), quoteVault: fixtureAddress(7), teamSlot: fixtureAddress(8),
25
+ });
26
+
27
+ export function launchV2Fixture(v: Record<string, unknown> = {}): { address: string; data: Uint8Array } {
28
+ const k = fixtureKeys();
29
+ return {
30
+ address: k.launch,
31
+ data: encodeAccountV2("LaunchV2", {
32
+ createdAt: 1_000n, creator: k.creator, quoteMint: k.quoteMint, quoteTokenProgram: TOKEN_PROGRAM_ID, baseMint: k.baseMint, tokenVault: k.tokenVault,
33
+ quoteVault: k.quoteVault, creatorRef: [k.creator, k.creator, k.creator], ...v,
34
+ }),
35
+ };
36
+ }
37
+
38
+ export function teamSlotFixture(members: readonly { key: string; kind?: number; state?: number }[] = []): { address: string; data: Uint8Array } {
39
+ const k = fixtureKeys();
40
+ if (members.length > 10) throw new RangeError("a Team Slot holds at most 10 members");
41
+ const ms = Array.from({ length: 10 }, (_, i) => ({ key: members[i] ? addressBytes(members[i].key) : new Uint8Array(32), kind: members[i]?.kind ?? 0, state: members[i] ? members[i].state ?? 2 : 0 }));
42
+ return { address: k.teamSlot, data: encodeAccount("TeamSlot", { memberCount: members.length, flags: 1, launch: k.launch, creator: k.creator, members: ms }) };
43
+ }
44
+
45
+ export function holderPositionFixture(v: { amount?: bigint; owed?: bigint; indexSnap?: bigint } = {}): Uint8Array {
46
+ const k = fixtureKeys();
47
+ return encodeAccountV2("HolderPosition", { launch: k.launch, owner: k.wallet, amount: v.amount ?? 0n, indexSnap: v.indexSnap ?? 0n, owed: v.owed ?? 0n });
48
+ }
49
+
50
+ export function holderBookFixture(v: { index?: bigint; w?: bigint; carry?: bigint } = {}): Uint8Array {
51
+ const k = fixtureKeys();
52
+ return encodeAccountV2("HolderBook", { launch: k.launch, mint: k.baseMint, w: v.w ?? 0n, index: v.index ?? 0n, carry: v.carry ?? 0n, bookedTotal: 0n, paidTotal: 0n });
53
+ }
@@ -0,0 +1,29 @@
1
+
2
+ import { EVM_FUNCTION_SELECTORS } from "./interface.gen.ts";
3
+ import type { EvmFunctionSelectorRow } from "./interface.gen.ts";
4
+
5
+ export { CLAIM_BITS, CLAIM_KNOWN_MASKS, CLAIM_RESERVED, EVM_FUNCTION_SELECTORS, PROGRAM_IDS } from "./interface.gen.ts";
6
+ export type { EvmFunctionSelectorRow } from "./interface.gen.ts";
7
+ import { CLAIM_BITS, CLAIM_RESERVED } from "./interface.gen.ts";
8
+
9
+ export const CLAIM_CREATOR = CLAIM_BITS.solana.creator;
10
+ export const CLAIM_CREATOR_REF = CLAIM_BITS.solana.creatorRef;
11
+ export const CLAIM_TEAM_SLOT = CLAIM_BITS.solana.teamSlot;
12
+ export const CLAIM_TRADER_REF = CLAIM_BITS.solana.traderRef;
13
+
14
+ export const CLAIM_RESERVED_HOLDER = CLAIM_RESERVED.solana.holderV1;
15
+
16
+ export const CLAIM_EXTRA = CLAIM_RESERVED.solana.extra;
17
+
18
+ export const CLAIM_TEAM_BUY = CLAIM_BITS.solana.teamBuy;
19
+
20
+ export const CLAIM_SHARE_BOUGHT = CLAIM_BITS.solana.shareBought;
21
+
22
+ export function evmFunction(name: string, source?: string): EvmFunctionSelectorRow {
23
+ const rows = EVM_FUNCTION_SELECTORS.filter((r) => r.name === name && (source === undefined || r.sources.includes(source)));
24
+ if (rows.length === 0) throw new Error(`no printed EVM function ${name}${source ? ` in ${source}` : ""}`);
25
+ if (rows.length > 1) throw new Error(`${name} is overloaded (${rows.map((r) => r.signature).join(", ")}): pass the source module`);
26
+ return rows[0];
27
+ }
28
+
29
+ export const evmSignature = (name: string, source?: string): string => evmFunction(name, source).signature;
@@ -0,0 +1,153 @@
1
+
2
+
3
+ export const PROGRAM_IDS = {"floorAmm":"GUhcaRccPyjdXtXmRWWopvsERfTEweqSS1Sa1FsFLooR","floorHook":"HVo1eRwj5SHtjkmHa4cVSV5KeL2BenN2d5qM2bqFLooR","upgradeTimelock":"87UhRsuVHieTz8ZTWHW7YMGQCYgh5TJQjogQ9UbxTiME"};
4
+
5
+ export const CLAIM_BITS = {"solana":{"creator":1,"creatorRef":2,"teamSlot":4,"traderRef":8,"teamBuy":128,"shareBought":256,"holder":512,"payout":null},"evm":{"creator":1,"creatorRef":2,"teamSlot":4,"traderRef":8,"teamBuy":128,"shareBought":256,"holder":512,"payout":64}};
6
+
7
+ export const CLAIM_RESERVED = {"solana":{"holderV1":16,"payout":64,"extra":32},"evm":{"holderV1":16,"extra":32}};
8
+
9
+ export const CLAIM_KNOWN_MASKS = {"solana":{"claim":143,"claimWideV1":399,"v2":911},"evm":{"v1":111,"v2":975}};
10
+
11
+ export interface EvmFunctionSelectorRow {
12
+ readonly name: string;
13
+ readonly signature: string;
14
+
15
+ readonly selector: string;
16
+
17
+ readonly sources: readonly string[];
18
+ }
19
+
20
+ export const EVM_FUNCTION_SELECTORS: readonly EvmFunctionSelectorRow[] = [
21
+ { name: "acceptAuthority", signature: "acceptAuthority()", selector: "0x1580798f", sources: ["floorAmm"] },
22
+ { name: "accounted", signature: "accounted(address)", selector: "0xee1a56ce", sources: ["floorAmm"] },
23
+ { name: "addPreset", signature: "addPreset(uint8,bytes)", selector: "0xb88257b1", sources: ["floorAmm"] },
24
+ { name: "addQuote", signature: "addQuote(address,uint256,uint256)", selector: "0x488c664b", sources: ["floorAmm"] },
25
+ { name: "addReward", signature: "addReward(uint256)", selector: "0x74de4ec4", sources: ["floorTokenIndexed"] },
26
+ { name: "allowance", signature: "allowance(address,address)", selector: "0xdd62ed3e", sources: ["floorToken","floorTokenIndexed"] },
27
+ { name: "approve", signature: "approve(address,uint256)", selector: "0x095ea7b3", sources: ["floorToken","floorTokenIndexed"] },
28
+ { name: "authority", signature: "authority()", selector: "0xbf7e214f", sources: ["floorAmm"] },
29
+ { name: "balanceOf", signature: "balanceOf(address)", selector: "0x70a08231", sources: ["floorToken","floorTokenIndexed"] },
30
+ { name: "bidMoney", signature: "bidMoney(uint256)", selector: "0x8e403c51", sources: ["floorAmmViewsV2"] },
31
+ { name: "bindHandle", signature: "bindHandle(bytes32,address,address[],uint256,bytes,bytes)", selector: "0xcea3463e", sources: ["floorAmm"] },
32
+ { name: "bookEngine", signature: "bookEngine()", selector: "0x72148c77", sources: ["floorAmmV2"] },
33
+ { name: "bookState", signature: "bookState()", selector: "0x2c14e3f2", sources: ["floorTokenIndexed"] },
34
+ { name: "bookTotals", signature: "bookTotals()", selector: "0xbffc2073", sources: ["floorTokenIndexed"] },
35
+ { name: "burn", signature: "burn(uint256)", selector: "0x42966c68", sources: ["floorToken","floorTokenIndexed"] },
36
+ { name: "burnFrom", signature: "burnFrom(address,uint256)", selector: "0x79cc6790", sources: ["floorToken","floorTokenIndexed"] },
37
+ { name: "burnTeamV2", signature: "burnTeamV2(uint256,uint8,uint256)", selector: "0x2f7bf11b", sources: ["floorAmmClaimsV2"] },
38
+ { name: "buy", signature: "buy(uint256,uint256,uint256,address,uint256)", selector: "0x102d8c79", sources: ["floorAmm","floorAmmV2"] },
39
+ { name: "buyFromBalance", signature: "buyFromBalance(uint256,uint256,address,address,uint256)", selector: "0x5f9f56d2", sources: ["floorAmm","floorAmmV2"] },
40
+ { name: "buyWithEth", signature: "buyWithEth(uint256,bytes,uint256,uint256,address,uint256)", selector: "0xef8772c4", sources: ["floorZap"] },
41
+ { name: "buyWithToken", signature: "buyWithToken(uint256,address,uint256,bytes,uint256,uint256,address,uint256)", selector: "0x9fd30605", sources: ["floorZap"] },
42
+ { name: "checkPreset", signature: "checkPreset(bytes)", selector: "0x6337513e", sources: ["floorAmm"] },
43
+ { name: "circulatingOf", signature: "circulatingOf(uint256)", selector: "0x72812fcf", sources: ["floorAmmViewsV2"] },
44
+ { name: "claim", signature: "claim(address,uint256,uint256[],address[])", selector: "0xa461a90d", sources: ["floorAmm","floorAmmClaimsV2"] },
45
+ { name: "claimPayoutTo", signature: "claimPayoutTo(address,address)", selector: "0xc14ab75d", sources: ["floorAmm"] },
46
+ { name: "clearTraderRef", signature: "clearTraderRef(address)", selector: "0x53550430", sources: ["floorAmm"] },
47
+ { name: "createBookEngine", signature: "createBookEngine()", selector: "0x0fdf26a7", sources: ["floorAmmCreateV2"] },
48
+ { name: "createLaunch", signature: "createLaunch((uint8,address,string,string,uint256,uint256,bool,bytes32,uint256,uint16))", selector: "0x25b62f18", sources: ["floorAmm","floorAmmCreateV2"] },
49
+ { name: "createPaused", signature: "createPaused()", selector: "0xbac7b497", sources: ["floorAmm"] },
50
+ { name: "creditBacking", signature: "creditBacking(uint256,uint256)", selector: "0x1f341504", sources: ["floorAmmV2"] },
51
+ { name: "DEAD", signature: "DEAD()", selector: "0x03fd2a45", sources: ["floorTokenIndexed"] },
52
+ { name: "decimals", signature: "decimals()", selector: "0x313ce567", sources: ["floorToken","floorTokenIndexed"] },
53
+ { name: "decodeRow", signature: "decodeRow(bytes)", selector: "0x8fff698d", sources: ["floorAmmCreateV2"] },
54
+ { name: "deletePreset", signature: "deletePreset(uint8)", selector: "0xb2d0d2a5", sources: ["floorAmm"] },
55
+ { name: "DOMAIN_SEPARATOR", signature: "DOMAIN_SEPARATOR()", selector: "0x3644e515", sources: ["floorToken","floorTokenIndexed"] },
56
+ { name: "eip712Domain", signature: "eip712Domain()", selector: "0x84b0196e", sources: ["floorTokenIndexed"] },
57
+ { name: "floorAmm", signature: "floorAmm()", selector: "0x78164d52", sources: ["floorZap"] },
58
+ { name: "floorTokenAccrued", signature: "floorTokenAccrued(address)", selector: "0xf3a261f9", sources: ["floorAmm"] },
59
+ { name: "handleOwed", signature: "handleOwed(bytes32,address)", selector: "0xaad2ed5c", sources: ["floorAmm"] },
60
+ { name: "handleWallet", signature: "handleWallet(bytes32)", selector: "0xc6da686d", sources: ["floorAmm"] },
61
+ { name: "holderBook", signature: "holderBook(uint256)", selector: "0xf5d23b14", sources: ["floorAmmViewsV2"] },
62
+ { name: "holderBucket", signature: "holderBucket(address)", selector: "0x088806d0", sources: ["floorAmm"] },
63
+ { name: "holderDest", signature: "holderDest()", selector: "0x84a6263a", sources: ["floorAmm"] },
64
+ { name: "initialize", signature: "initialize(address,address,address,address)", selector: "0xf8c8765e", sources: ["floorAmm"] },
65
+ { name: "initialize", signature: "initialize(string,string,uint256)", selector: "0xb119490e", sources: ["floorTokenIndexed"] },
66
+ { name: "launchBook", signature: "launchBook(uint256)", selector: "0x926310f1", sources: ["floorAmmViewsV2"] },
67
+ { name: "launchCount", signature: "launchCount()", selector: "0x27cca59f", sources: ["floorAmm","floorAmmViewsV2"] },
68
+ { name: "launchFeeCurve", signature: "launchFeeCurve(uint256)", selector: "0xc598083f", sources: ["floorAmmViewsV2"] },
69
+ { name: "launchId", signature: "launchId()", selector: "0x35f6efa9", sources: ["floorToken","floorTokenIndexed"] },
70
+ { name: "launchMilestones", signature: "launchMilestones(uint256)", selector: "0x2414ccf1", sources: ["floorAmmViewsV2"] },
71
+ { name: "launchOf", signature: "launchOf(address)", selector: "0x029282d7", sources: ["floorAmm","floorAmmViewsV2"] },
72
+ { name: "launchOfPair", signature: "launchOfPair(bytes32)", selector: "0x08415ca8", sources: ["floorAmmViewsV2"] },
73
+ { name: "launchQuote", signature: "launchQuote(uint256)", selector: "0x98032919", sources: ["floorAmm","floorAmmViewsV2"] },
74
+ { name: "launchState", signature: "launchState(uint256)", selector: "0xac3307e8", sources: ["floorAmm","floorAmmViewsV2"] },
75
+ { name: "launchToken", signature: "launchToken(uint256)", selector: "0x6a19197b", sources: ["floorAmm","floorAmmViewsV2"] },
76
+ { name: "metadataBase", signature: "metadataBase()", selector: "0x65b973c3", sources: ["floorAmm"] },
77
+ { name: "metadataURI", signature: "metadataURI()", selector: "0x03ee438c", sources: ["floorToken","floorTokenIndexed"] },
78
+ { name: "moveHandleOwed", signature: "moveHandleOwed(bytes32,address[])", selector: "0xc43594a1", sources: ["floorAmm"] },
79
+ { name: "name", signature: "name()", selector: "0x06fdde03", sources: ["floorToken","floorTokenIndexed"] },
80
+ { name: "NATIVE", signature: "NATIVE()", selector: "0xa0cf0aea", sources: ["floorAmm"] },
81
+ { name: "nativeCreateFee", signature: "nativeCreateFee()", selector: "0x10b51e45", sources: ["floorAmm"] },
82
+ { name: "nextModule", signature: "nextModule()", selector: "0xf85abfc7", sources: ["floorAmmV2","floorAmmViewsV2","floorAmmCreateV2","floorAmmClaimsV2"] },
83
+ { name: "nextPresetId", signature: "nextPresetId()", selector: "0xc8a768e6", sources: ["floorAmm"] },
84
+ { name: "nonces", signature: "nonces(address)", selector: "0x7ecebe00", sources: ["floorToken","floorTokenIndexed"] },
85
+ { name: "noteBurn", signature: "noteBurn(uint256)", selector: "0x6db7cd01", sources: ["floorAmmCreateV2"] },
86
+ { name: "noteDead", signature: "noteDead(uint256)", selector: "0xbdf3b0de", sources: ["floorAmmCreateV2"] },
87
+ { name: "optedIn", signature: "optedIn(address)", selector: "0x4824b8fd", sources: ["floorTokenIndexed"] },
88
+ { name: "optIn", signature: "optIn()", selector: "0x5b48684e", sources: ["floorTokenIndexed"] },
89
+ { name: "owedOf", signature: "owedOf(address,address)", selector: "0xfacba08d", sources: ["floorAmm"] },
90
+ { name: "owedOfMany", signature: "owedOfMany(address,address[])", selector: "0xa1efa4ba", sources: ["floorAmm"] },
91
+ { name: "owedV2", signature: "owedV2(address,uint256[],address[])", selector: "0xdd3ee1ef", sources: ["floorAmmViewsV2"] },
92
+ { name: "pairIdOf", signature: "pairIdOf(uint256)", selector: "0x83a74ea3", sources: ["floorAmmViewsV2"] },
93
+ { name: "payoutOwed", signature: "payoutOwed(address,address)", selector: "0xae3f9120", sources: ["floorAmm"] },
94
+ { name: "pendingAuthority", signature: "pendingAuthority()", selector: "0xfabb94bb", sources: ["floorAmm"] },
95
+ { name: "permit", signature: "permit(address,address,uint256,uint256,uint8,bytes32,bytes32)", selector: "0xd505accf", sources: ["floorToken","floorTokenIndexed"] },
96
+ { name: "platformOwed", signature: "platformOwed(address)", selector: "0x240b9586", sources: ["floorAmm"] },
97
+ { name: "positionOf", signature: "positionOf(address)", selector: "0xfd2d39c5", sources: ["floorTokenIndexed"] },
98
+ { name: "predictToken", signature: "predictToken(address,bytes32)", selector: "0x486e36c8", sources: ["floorAmm","floorAmmCreateV2"] },
99
+ { name: "presetRow", signature: "presetRow(uint8)", selector: "0xa0c15861", sources: ["floorAmm"] },
100
+ { name: "priceUpdater", signature: "priceUpdater()", selector: "0xfc612a8d", sources: ["floorAmm"] },
101
+ { name: "program", signature: "program()", selector: "0xc860ebc6", sources: ["floorToken","floorTokenIndexed"] },
102
+ { name: "proxiableUUID", signature: "proxiableUUID()", selector: "0x52d1902d", sources: ["floorAmmV2"] },
103
+ { name: "quoteBuy", signature: "quoteBuy(uint256,uint256,address)", selector: "0xec7a34c9", sources: ["floorAmm","floorAmmV2"] },
104
+ { name: "quoteEntry", signature: "quoteEntry(address)", selector: "0x77665076", sources: ["floorAmm"] },
105
+ { name: "quoteRisk", signature: "quoteRisk(address)", selector: "0x1461d14e", sources: ["floorAmm"] },
106
+ { name: "quotes", signature: "quotes()", selector: "0xd6a5d7db", sources: ["floorAmm"] },
107
+ { name: "quoteSell", signature: "quoteSell(uint256,uint256,address)", selector: "0x0cff08d1", sources: ["floorAmm","floorAmmV2"] },
108
+ { name: "referralAuthority", signature: "referralAuthority()", selector: "0x2fe0a99a", sources: ["floorAmm"] },
109
+ { name: "releaseSkipped", signature: "releaseSkipped(address)", selector: "0x215fa9eb", sources: ["floorTokenIndexed"] },
110
+ { name: "router", signature: "router()", selector: "0xf887ea40", sources: ["floorZap"] },
111
+ { name: "sell", signature: "sell(uint256,uint256,uint256,address,uint256)", selector: "0xbadb999b", sources: ["floorAmm","floorAmmV2"] },
112
+ { name: "sellFromBalance", signature: "sellFromBalance(uint256,uint256,address,uint256)", selector: "0x611b00a8", sources: ["floorAmm","floorAmmV2"] },
113
+ { name: "sellWithPermit", signature: "sellWithPermit(uint256,uint256,uint256,address,uint256,uint256,uint8,bytes32,bytes32)", selector: "0x2ab030d3", sources: ["floorAmm","floorAmmV2"] },
114
+ { name: "setCreatePaused", signature: "setCreatePaused(bool)", selector: "0x83bcec85", sources: ["floorAmm"] },
115
+ { name: "setHolderDest", signature: "setHolderDest(address)", selector: "0x6ad3e66d", sources: ["floorAmm"] },
116
+ { name: "setMetadataBase", signature: "setMetadataBase(string)", selector: "0xd3811c0f", sources: ["floorAmm"] },
117
+ { name: "setNativeCreateFee", signature: "setNativeCreateFee(uint256)", selector: "0xa4433667", sources: ["floorAmm"] },
118
+ { name: "setPresetEnabled", signature: "setPresetEnabled(uint8,bool)", selector: "0x673fb9a9", sources: ["floorAmm"] },
119
+ { name: "setPriceUpdater", signature: "setPriceUpdater(address)", selector: "0x97c4a5f3", sources: ["floorAmm"] },
120
+ { name: "setQuoteCap", signature: "setQuoteCap(address,uint128)", selector: "0x42adf398", sources: ["floorAmm"] },
121
+ { name: "setQuotePrice", signature: "setQuotePrice(address,uint256)", selector: "0x3857ed9e", sources: ["floorAmm"] },
122
+ { name: "setReferralAuthority", signature: "setReferralAuthority(address)", selector: "0x46325d7a", sources: ["floorAmm"] },
123
+ { name: "setTimelock", signature: "setTimelock(address)", selector: "0xbdacb303", sources: ["floorAmm"] },
124
+ { name: "setTraderRef", signature: "setTraderRef(address,address[3],uint256,bytes,bytes)", selector: "0xd7426758", sources: ["floorAmm"] },
125
+ { name: "setTreasury", signature: "setTreasury(address)", selector: "0xf0f44260", sources: ["floorAmm"] },
126
+ { name: "simBuy", signature: "simBuy(uint256,uint256,address)", selector: "0xf69acbed", sources: ["floorAmmV2"] },
127
+ { name: "simSell", signature: "simSell(uint256,uint256,address)", selector: "0xd3536ecd", sources: ["floorAmmV2"] },
128
+ { name: "symbol", signature: "symbol()", selector: "0x95d89b41", sources: ["floorToken","floorTokenIndexed"] },
129
+ { name: "takeOwed", signature: "takeOwed(address)", selector: "0x5e9d234b", sources: ["floorTokenIndexed"] },
130
+ { name: "teamShareBuy", signature: "teamShareBuy(uint256,uint256,uint256,uint256)", selector: "0x5ca91374", sources: ["floorAmm","floorAmmV2"] },
131
+ { name: "teamShareBuyAndClaim", signature: "teamShareBuyAndClaim(uint256,uint256,uint256,uint256)", selector: "0xc7f1048c", sources: ["floorAmmViewsV2"] },
132
+ { name: "teamShareOf", signature: "teamShareOf(uint256,address)", selector: "0xb2280af2", sources: ["floorAmm","floorAmmViewsV2"] },
133
+ { name: "teamSlotAdd", signature: "teamSlotAdd(uint256,bytes32,uint8,uint256,bool)", selector: "0xd5402e81", sources: ["floorAmm","floorAmmClaimsV2"] },
134
+ { name: "teamSlotOf", signature: "teamSlotOf(uint256)", selector: "0x8744aded", sources: ["floorAmmViewsV2"] },
135
+ { name: "timelock", signature: "timelock()", selector: "0xd33219b4", sources: ["floorAmm"] },
136
+ { name: "TOKEN_SCALE", signature: "TOKEN_SCALE()", selector: "0xcae07d2a", sources: ["floorTokenIndexed"] },
137
+ { name: "tokenImplV2", signature: "tokenImplV2()", selector: "0x01b9b386", sources: ["floorAmmCreateV2"] },
138
+ { name: "TOTAL_SUPPLY", signature: "TOTAL_SUPPLY()", selector: "0x902d55a5", sources: ["floorTokenIndexed"] },
139
+ { name: "totalSupply", signature: "totalSupply()", selector: "0x18160ddd", sources: ["floorToken","floorTokenIndexed"] },
140
+ { name: "traderRef", signature: "traderRef(address)", selector: "0xcfc18291", sources: ["floorAmm","floorAmmViewsV2"] },
141
+ { name: "transfer", signature: "transfer(address,uint256)", selector: "0xa9059cbb", sources: ["floorToken","floorTokenIndexed"] },
142
+ { name: "transferAuthority", signature: "transferAuthority(address)", selector: "0x3078db6c", sources: ["floorAmm"] },
143
+ { name: "transferFrom", signature: "transferFrom(address,address,uint256)", selector: "0x23b872dd", sources: ["floorToken","floorTokenIndexed"] },
144
+ { name: "treasury", signature: "treasury()", selector: "0x61d027b3", sources: ["floorAmm"] },
145
+ { name: "unlockCreatorBuy", signature: "unlockCreatorBuy(uint256)", selector: "0xf03d6d5e", sources: ["floorAmm","floorAmmClaimsV2"] },
146
+ { name: "updatePreset", signature: "updatePreset(uint8,bytes)", selector: "0x005d9e72", sources: ["floorAmm"] },
147
+ { name: "updateQuote", signature: "updateQuote(address,bool,uint256,uint256)", selector: "0x21593d6e", sources: ["floorAmm"] },
148
+ { name: "UPGRADE_INTERFACE_VERSION", signature: "UPGRADE_INTERFACE_VERSION()", selector: "0xad3cb1cc", sources: ["floorAmmV2"] },
149
+ { name: "upgradeToAndCall", signature: "upgradeToAndCall(address,bytes)", selector: "0x4f1ef286", sources: ["floorAmmV2"] },
150
+ { name: "withdrawHolder", signature: "withdrawHolder(address,uint256)", selector: "0xfb90c8bf", sources: ["floorAmm","floorAmmCreateV2"] },
151
+ { name: "withdrawPlatform", signature: "withdrawPlatform(address,uint256)", selector: "0x7fe33965", sources: ["floorAmm","floorAmmCreateV2"] },
152
+ { name: "withdrawPlatformMany", signature: "withdrawPlatformMany(uint256[])", selector: "0x7c74681b", sources: ["floorAmmCreateV2"] },
153
+ ];
package/src/handle.ts ADDED
@@ -0,0 +1,22 @@
1
+
2
+
3
+ import { keccak256 } from "./evm/keccak.ts";
4
+ import { hex } from "./codec.ts";
5
+
6
+ export function handleKeyPreimage(platform: string, handle: string): string {
7
+ const p = platform.trim().toLowerCase();
8
+ if (!/^[a-z0-9]+$/.test(p)) throw new RangeError(`a platform is its lowercase short name (e.g. "x"): ${JSON.stringify(platform)}`);
9
+ let h = handle.trim();
10
+ if (h.startsWith("@")) h = h.slice(1);
11
+ h = h.toLowerCase();
12
+ if (h.length === 0 || /[\s@:]/u.test(h)) throw new RangeError(`a handle has no spaces, no ':' and no '@' but one leading: ${JSON.stringify(handle)}`);
13
+ return `${p}:${h}`;
14
+ }
15
+
16
+ export function teamSlotHandleKey(platform: string, handle: string): Uint8Array {
17
+ return keccak256(new TextEncoder().encode(handleKeyPreimage(platform, handle)));
18
+ }
19
+
20
+ export function teamSlotHandleId(platform: string, handle: string): string {
21
+ return "0x" + hex(teamSlotHandleKey(platform, handle));
22
+ }