@floorlaunchpad/sdk 0.1.0 → 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
package/src/sha256.ts ADDED
@@ -0,0 +1,61 @@
1
+
2
+
3
+ const K = new Uint32Array([
4
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
5
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
6
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
7
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
8
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
9
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
10
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
11
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
12
+ ]);
13
+
14
+ const rotr = (x: number, n: number): number => (x >>> n) | (x << (32 - n));
15
+
16
+ export function sha256(msg: Uint8Array): Uint8Array {
17
+ const bitLen = BigInt(msg.length) * 8n;
18
+ const padded = new Uint8Array(Math.ceil((msg.length + 9) / 64) * 64);
19
+ padded.set(msg);
20
+ padded[msg.length] = 0x80;
21
+ for (let i = 0; i < 8; i++) padded[padded.length - 1 - i] = Number((bitLen >> BigInt(8 * i)) & 0xffn);
22
+ const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
23
+ const w = new Uint32Array(64);
24
+ for (let off = 0; off < padded.length; off += 64) {
25
+ for (let i = 0; i < 16; i++) {
26
+ const j = off + 4 * i;
27
+ w[i] = (padded[j] << 24) | (padded[j + 1] << 16) | (padded[j + 2] << 8) | padded[j + 3];
28
+ }
29
+ for (let i = 16; i < 64; i++) {
30
+ const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
31
+ const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
32
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;
33
+ }
34
+ let [a, b, c, d, e, f, g, hh] = h;
35
+ for (let i = 0; i < 64; i++) {
36
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
37
+ const ch = (e & f) ^ (~e & g);
38
+ const t1 = (hh + S1 + ch + K[i] + w[i]) | 0;
39
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
40
+ const maj = (a & b) ^ (a & c) ^ (b & c);
41
+ const t2 = (S0 + maj) | 0;
42
+ hh = g;
43
+ g = f;
44
+ f = e;
45
+ e = (d + t1) | 0;
46
+ d = c;
47
+ c = b;
48
+ b = a;
49
+ a = (t1 + t2) | 0;
50
+ }
51
+ h[0] += a; h[1] += b; h[2] += c; h[3] += d; h[4] += e; h[5] += f; h[6] += g; h[7] += hh;
52
+ }
53
+ const out = new Uint8Array(32);
54
+ for (let i = 0; i < 8; i++) {
55
+ out[4 * i] = h[i] >>> 24;
56
+ out[4 * i + 1] = (h[i] >>> 16) & 0xff;
57
+ out[4 * i + 2] = (h[i] >>> 8) & 0xff;
58
+ out[4 * i + 3] = h[i] & 0xff;
59
+ }
60
+ return out;
61
+ }
@@ -0,0 +1,25 @@
1
+
2
+
3
+ import { base58Encode, readUintLE } from "../codec.ts";
4
+ import type { LookupTable } from "./tx.ts";
5
+
6
+ export const LOOKUP_TABLE_META_SIZE = 56;
7
+
8
+ export interface LookupTableAccount extends LookupTable {
9
+ deactivationSlot: bigint;
10
+ lastExtendedSlot: bigint;
11
+ authority: string | null;
12
+ }
13
+
14
+ export function decodeLookupTable(address: string, data: Uint8Array): LookupTableAccount {
15
+ if (data.length < LOOKUP_TABLE_META_SIZE || readUintLE(data, 0, 4) !== 1n || (data.length - LOOKUP_TABLE_META_SIZE) % 32 !== 0) throw new RangeError("not a lookup table account");
16
+ const addresses: string[] = [];
17
+ for (let o = LOOKUP_TABLE_META_SIZE; o < data.length; o += 32) addresses.push(base58Encode(data.slice(o, o + 32)));
18
+ return {
19
+ address,
20
+ addresses,
21
+ deactivationSlot: readUintLE(data, 4, 8),
22
+ lastExtendedSlot: readUintLE(data, 12, 8),
23
+ authority: data[21] === 1 ? base58Encode(data.slice(22, 54)) : null,
24
+ };
25
+ }
@@ -0,0 +1,393 @@
1
+
2
+
3
+ import { addressBytes, base58Encode, hex } from "../../codec.ts";
4
+ import { accountDiscriminator } from "../instruction.ts";
5
+
6
+ type FieldType = string;
7
+ export type Layout = readonly (readonly [name: string, type: FieldType])[];
8
+
9
+ export const SLOT_MEMBER: Layout = [
10
+ ["key", "bytes:32"],
11
+ ["kind", "u8"],
12
+ ["state", "u8"],
13
+ ["pad", "bytes:6"],
14
+ ["paid", "u64"],
15
+ ["requested", "u64"],
16
+ ["earned", "u64"],
17
+ ["withdrawn", "u64"],
18
+ ["reserved", "bytes:8"],
19
+ ];
20
+
21
+ export const CONFIG: Layout = [
22
+ ["version", "u8"],
23
+ ["bump", "u8"],
24
+ ["create_paused", "u8"],
25
+ ["next_preset_id", "u8"],
26
+ ["pad0", "bytes:4"],
27
+ ["authority", "pubkey"],
28
+ ["pending_authority", "pubkey"],
29
+ ["timelock", "pubkey"],
30
+ ["referral_authority", "pubkey"],
31
+ ["launch_count", "u64"],
32
+ ["holder_dest", "pubkey"],
33
+
34
+ ["native_create_fee", "u64"],
35
+ ["native_fees_owed", "u64"],
36
+
37
+ ["metadata_base", "bytes:72"],
38
+ ["metadata_base_len", "u8"],
39
+
40
+ ["pad_metadata_base_len", "bytes:7"],
41
+
42
+ ["treasury", "pubkey"],
43
+
44
+ ["price_updater", "pubkey"],
45
+ ];
46
+
47
+ export const QUOTE_ENTRY: Layout = [
48
+ ["version", "u8"],
49
+ ["bump", "u8"],
50
+ ["enabled", "u8"],
51
+ ["decimals", "u8"],
52
+ ["pad0", "bytes:4"],
53
+ ["mint", "pubkey"],
54
+ ["token_program", "pubkey"],
55
+ ["create_fee", "u64"],
56
+ ["usd_cents_x64", "u128l"],
57
+ ["launches", "u64"],
58
+ ["updated_at", "i64"],
59
+
60
+ ["admitted_caps", "u32"],
61
+ ["pad1", "u32"],
62
+ ["reserved", "bytes:56"],
63
+ ];
64
+
65
+ export const TEAM_SLOT: Layout = [
66
+ ["version", "u8"],
67
+ ["bump", "u8"],
68
+ ["member_count", "u8"],
69
+ ["flags", "u8"],
70
+ ["rate_bps", "u16"],
71
+ ["pad0", "bytes:2"],
72
+ ["price", "u64"],
73
+ ["bought", "u64"],
74
+ ["reserved_total", "u64"],
75
+ ["opened_at", "i64"],
76
+ ["launch", "pubkey"],
77
+ ["creator", "pubkey"],
78
+ ["members", "SlotMember[10]"],
79
+ ["reserved", "bytes:64"],
80
+ ];
81
+
82
+ export const TRADER_REF: Layout = [
83
+ ["trader", "pubkey"],
84
+ ["quote_mint", "pubkey"],
85
+ ["tiers", "pubkey[3]"],
86
+ ["owed", "u64[3]"],
87
+ ["rolled", "u64[3]"],
88
+ ["bump", "u8"],
89
+ ["escrow_bump", "u8"],
90
+ ["revoked", "u8"],
91
+
92
+ ["pad0", "bytes:5"],
93
+ ["reserved", "bytes:24"],
94
+ ];
95
+
96
+ export const TRADER_LINK: Layout = [
97
+ ["wallet", "pubkey"],
98
+ ["tiers", "pubkey[3]"],
99
+ ["bump", "u8"],
100
+ ["reserved", "bytes:24"],
101
+ ];
102
+
103
+ export const REF_OWED: Layout = [
104
+ ["referrer", "pubkey"],
105
+ ["quote_mint", "pubkey"],
106
+ ["owed", "u64"],
107
+ ["paid", "u64"],
108
+ ["bump", "u8"],
109
+ ["pad0", "bytes:7"],
110
+ ["reserved", "bytes:24"],
111
+ ];
112
+
113
+ export const GENESIS_RAISE: Layout = [
114
+ ["version", "u8"],
115
+ ["bump", "u8"],
116
+ ["accepted", "u8"],
117
+ ["vault_bump", "u8"],
118
+ ["count", "u16"],
119
+ ["pad0", "bytes:2"],
120
+ ["old_sale", "pubkey"],
121
+ ["total_migrated", "u64"],
122
+ ["donation", "u64"],
123
+ ["accepted_at", "i64"],
124
+ ["accepted_slot", "u64"],
125
+
126
+ ["preset_id", "u8"],
127
+ ["opened", "u8"],
128
+ ["pad1", "bytes:6"],
129
+ ["cap", "u64"],
130
+ ["ends_at", "i64"],
131
+ ["migrated_refunded", "u64"],
132
+ ["phase3_total", "u64"],
133
+ ["raised_final", "u64"],
134
+ ["tokens_out", "u64"],
135
+ ["tokens_claimed", "u64"],
136
+ ["weight_total", "u64"],
137
+ ["launch", "pubkey"],
138
+ ["base_mint", "pubkey"],
139
+ ["deployer", "pubkey"],
140
+
141
+ ["refund_total", "u64"],
142
+ ["refund_claimed", "u64"],
143
+ ["credit_claimed", "u64"],
144
+ ["refund_owed", "u64"],
145
+ ["refund_dust", "u64"],
146
+
147
+ ["creator", "pubkey"],
148
+ ["list_root", "bytes:32"],
149
+ ["listed_reserve", "u64"],
150
+ ["listed_total", "u64"],
151
+
152
+ ["wagmi_preset_id", "u8"],
153
+ ["wagmi_opened", "u8"],
154
+ ["pad2", "bytes:6"],
155
+ ["usdc_converted", "u64"],
156
+ ["sol_unconverted", "u64"],
157
+ ["wagmi_usdc", "u64"],
158
+ ["wagmi_floor_in", "u64"],
159
+ ["wagmi_floor_refund", "u64"],
160
+ ["wagmi_floor_refund_claimed", "u64"],
161
+ ["wagmi_tokens_out", "u64"],
162
+ ["wagmi_tokens_claimed", "u64"],
163
+ ["wagmi_launch", "pubkey"],
164
+ ["wagmi_mint", "pubkey"],
165
+ ["sol_converted", "u64"],
166
+ ["floor_usdc_in", "u64"],
167
+ ["usdc_refund_total", "u64"],
168
+ ["usdc_refund_claimed", "u64"],
169
+ ["usdc_refund_owed", "u64"],
170
+ ["usdc_excess", "u64"],
171
+
172
+ ["wagmi_credit_claimed", "u64"],
173
+ ["wagmi_floor_dust", "u64"],
174
+
175
+ ["wagmi_cap_tokens", "u64"],
176
+ ["wagmi_over_cap_floor", "u64"],
177
+ ["wagmi_over_cap_out", "u64"],
178
+
179
+ ["wagmi_buy_fees", "u64[5]"],
180
+ ];
181
+
182
+ export const GENESIS_ALLOCATION: Layout = [
183
+ ["wallet", "pubkey"],
184
+ ["contributed", "u64"],
185
+ ["claimed_tokens", "u64"],
186
+ ["refunded", "u64"],
187
+ ["bump", "u8"],
188
+ ["flags", "u8"],
189
+ ["pad0", "bytes:6"],
190
+ ["migrated", "u64"],
191
+
192
+ ["raise_refund", "u64"],
193
+ ["refund_owed", "u64"],
194
+
195
+ ["listed_old", "u64"],
196
+ ["listed", "u64"],
197
+
198
+ ["wagmi_claimed", "u64"],
199
+ ["usdc_refund", "u64"],
200
+ ["usdc_owed", "u64"],
201
+ ];
202
+
203
+ export const GENESIS_ALLOC_MIGRATED = 1;
204
+ export const GENESIS_ALLOC_REFUNDED = 2;
205
+ export const GENESIS_ALLOC_CLAIMED = 4;
206
+ export const GENESIS_ALLOC_WAGMI_CLAIMED = 8;
207
+
208
+ const NESTED: Record<string, Layout> = { SlotMember: SLOT_MEMBER };
209
+
210
+ export const LAYOUTS = { Config: CONFIG, QuoteEntry: QUOTE_ENTRY, TeamSlot: TEAM_SLOT, SlotMember: SLOT_MEMBER, TraderRef: TRADER_REF, TraderLink: TRADER_LINK, RefOwed: REF_OWED, GenesisRaise: GENESIS_RAISE, GenesisAllocation: GENESIS_ALLOCATION } as const;
211
+
212
+ function scalarSize(t: string): number {
213
+ switch (t) {
214
+ case "u8":
215
+ return 1;
216
+ case "u16":
217
+ return 2;
218
+ case "u32":
219
+ return 4;
220
+ case "u64":
221
+ case "i64":
222
+ return 8;
223
+ case "u128l":
224
+ return 16;
225
+ case "pubkey":
226
+ return 32;
227
+ }
228
+ if (t.startsWith("bytes:")) return Number(t.slice(6));
229
+ if (t in NESTED) return layoutSize(NESTED[t]);
230
+ throw new Error(`unknown field type ${t}`);
231
+ }
232
+
233
+ export function fieldSize(t: FieldType): number {
234
+ const m = /^(.+)\[(\d+)\]$/.exec(t);
235
+ return m ? scalarSize(m[1]) * Number(m[2]) : scalarSize(t);
236
+ }
237
+
238
+ export function layoutOffsets(l: Layout): [string, number, number][] {
239
+ let o = 0;
240
+ return l.map(([n, t]) => {
241
+ const s = fieldSize(t);
242
+ const r: [string, number, number] = [n, o, s];
243
+ o += s;
244
+ return r;
245
+ });
246
+ }
247
+
248
+ export function layoutSize(l: Layout): number {
249
+ return l.reduce((a, [, t]) => a + fieldSize(t), 0);
250
+ }
251
+
252
+ const camel = (s: string): string => s.replace(/_([a-z0-9])/g, (_, c: string) => c.toUpperCase());
253
+
254
+ function readUint(b: Uint8Array, o: number, n: number): bigint {
255
+ let v = 0n;
256
+ for (let i = n - 1; i >= 0; i--) v = (v << 8n) | BigInt(b[o + i]);
257
+ return v;
258
+ }
259
+
260
+ function readScalar(b: Uint8Array, o: number, t: string): unknown {
261
+ switch (t) {
262
+ case "u8":
263
+ case "u16":
264
+ case "u32":
265
+ return Number(readUint(b, o, scalarSize(t)));
266
+ case "u64":
267
+ return readUint(b, o, 8);
268
+ case "i64": {
269
+ const v = readUint(b, o, 8);
270
+ return v >= 1n << 63n ? v - (1n << 64n) : v;
271
+ }
272
+ case "u128l":
273
+ return readUint(b, o, 16);
274
+ case "pubkey":
275
+ return base58Encode(b.slice(o, o + 32));
276
+ }
277
+ if (t.startsWith("bytes:")) return b.slice(o, o + Number(t.slice(6)));
278
+ if (t in NESTED) return decodeStruct(NESTED[t], b, o);
279
+ throw new Error(`unknown field type ${t}`);
280
+ }
281
+
282
+ export function decodeStruct(l: Layout, b: Uint8Array, o = 0): Record<string, any> {
283
+ const out: Record<string, any> = {};
284
+ let at = o;
285
+ for (const [n, t] of l) {
286
+ const m = /^(.+)\[(\d+)\]$/.exec(t);
287
+ if (m) {
288
+ const s = scalarSize(m[1]);
289
+ out[camel(n)] = Array.from({ length: Number(m[2]) }, (_, i) => readScalar(b, at + i * s, m[1]));
290
+ } else out[camel(n)] = readScalar(b, at, t);
291
+ at += fieldSize(t);
292
+ }
293
+ return out;
294
+ }
295
+
296
+ function writeScalar(b: Uint8Array, o: number, t: string, v: any): void {
297
+ if (v === undefined) return;
298
+ if (t === "pubkey") {
299
+ b.set(addressBytes(v), o);
300
+ return;
301
+ }
302
+ if (t.startsWith("bytes:")) {
303
+ b.set(v, o);
304
+ return;
305
+ }
306
+ if (t in NESTED) {
307
+ encodeStructInto(NESTED[t], v, b, o);
308
+ return;
309
+ }
310
+ const n = scalarSize(t);
311
+ let x = BigInt(v);
312
+ if (t === "i64" && x < 0n) x += 1n << 64n;
313
+ for (let i = 0; i < n; i++) {
314
+ b[o + i] = Number(x & 0xffn);
315
+ x >>= 8n;
316
+ }
317
+ }
318
+
319
+ function encodeStructInto(l: Layout, v: Record<string, any>, b: Uint8Array, o: number): void {
320
+ let at = o;
321
+ for (const [n, t] of l) {
322
+ const x = v[camel(n)];
323
+ const m = /^(.+)\[(\d+)\]$/.exec(t);
324
+ if (m && x !== undefined) {
325
+ const s = scalarSize(m[1]);
326
+ (x as any[]).forEach((e, i) => writeScalar(b, at + i * s, m[1], e));
327
+ } else if (!m) writeScalar(b, at, t, x);
328
+ at += fieldSize(t);
329
+ }
330
+ }
331
+
332
+ export function encodeStruct(l: Layout, v: Record<string, any>): Uint8Array {
333
+ const b = new Uint8Array(layoutSize(l));
334
+ encodeStructInto(l, v, b, 0);
335
+ return b;
336
+ }
337
+
338
+ export function encodeAccount(name: keyof typeof LAYOUTS, v: Record<string, any>): Uint8Array {
339
+ const l = LAYOUTS[name];
340
+ const b = new Uint8Array(8 + layoutSize(l));
341
+ if (name !== "SlotMember") b.set(accountDiscriminator(name), 0);
342
+ encodeStructInto(l, v, b, 8);
343
+ return b;
344
+ }
345
+
346
+ export class AccountDecodeError extends Error {
347
+ constructor(detail: string) {
348
+ super(`floor_amm account: ${detail}`);
349
+ this.name = "AccountDecodeError";
350
+ }
351
+ }
352
+
353
+ export function decodeAccount(name: keyof typeof LAYOUTS, data: Uint8Array): Record<string, any> {
354
+ const l = LAYOUTS[name];
355
+ const d = accountDiscriminator(name);
356
+
357
+ if (data.length !== 8 + layoutSize(l)) throw new AccountDecodeError(`${name}: ${data.length} bytes, want ${8 + layoutSize(l)}`);
358
+ if (hex(data.slice(0, 8)) !== hex(d)) throw new AccountDecodeError(`${name}: wrong discriminator`);
359
+ return decodeStruct(l, data, 8);
360
+ }
361
+
362
+ export const decodeConfig = (d: Uint8Array) => decodeAccount("Config", d);
363
+ export const decodeQuoteEntry = (d: Uint8Array) => decodeAccount("QuoteEntry", d);
364
+ export const decodeTeamSlot = (d: Uint8Array) => decodeAccount("TeamSlot", d);
365
+ export const decodeTraderRef = (d: Uint8Array) => decodeAccount("TraderRef", d);
366
+ export const decodeTraderLink = (d: Uint8Array) => decodeAccount("TraderLink", d);
367
+ export const decodeRefOwed = (d: Uint8Array) => decodeAccount("RefOwed", d);
368
+ export const decodeGenesisRaise = (d: Uint8Array) => decodeAccount("GenesisRaise", d);
369
+ export const decodeGenesisAllocation = (d: Uint8Array) => decodeAccount("GenesisAllocation", d);
370
+
371
+ export function accountKind(data: Uint8Array): keyof typeof LAYOUTS | null {
372
+ const d = hex(data.slice(0, 8));
373
+ for (const name of Object.keys(LAYOUTS) as (keyof typeof LAYOUTS)[]) {
374
+ if (name === "SlotMember" || hex(accountDiscriminator(name)) !== d) continue;
375
+ if (data.length !== 8 + layoutSize(LAYOUTS[name])) throw new AccountDecodeError(`${name}: ${data.length} bytes, want ${8 + layoutSize(LAYOUTS[name])}`);
376
+ return name;
377
+ }
378
+ return null;
379
+ }
380
+
381
+ export const STATUS_LIVE = 1;
382
+
383
+ export const PRESET_CHECKED_ALL = 2;
384
+
385
+ export const PRESET_CHECKED_STEP1 = 1;
386
+ export const SLOT_ACTIVE = 1;
387
+ export const SLOT_FREE = 2;
388
+
389
+ export function metadataBaseOf(configData: Uint8Array): string {
390
+ const c = decodeConfig(configData);
391
+ const n = Math.min(Number(c.metadataBaseLen), 72);
392
+ return new TextDecoder().decode((c.metadataBase as Uint8Array).slice(0, n));
393
+ }
@@ -0,0 +1,66 @@
1
+
2
+
3
+ import { addressBytes, base58Encode } from "../../codec.ts";
4
+
5
+ export class Writer {
6
+ private parts: number[] = [];
7
+ uint(v: bigint | number, n: number): this {
8
+ let x = BigInt(v);
9
+ if (x < 0n || x >= 1n << BigInt(8 * n)) throw new RangeError(`a ${8 * n}-bit value out of range: ${v}`);
10
+ for (let i = 0; i < n; i++) {
11
+ this.parts.push(Number(x & 0xffn));
12
+ x >>= 8n;
13
+ }
14
+ return this;
15
+ }
16
+ u8 = (v: number): this => this.uint(v, 1);
17
+ u16 = (v: number): this => this.uint(v, 2);
18
+ u32 = (v: number): this => this.uint(v, 4);
19
+ u64 = (v: bigint): this => this.uint(v, 8);
20
+ u128 = (v: bigint): this => this.uint(v, 16);
21
+ bool = (v: boolean): this => this.u8(v ? 1 : 0);
22
+ pubkey = (a: string): this => this.bytes(addressBytes(a));
23
+ bytes(b: Uint8Array): this {
24
+ for (const x of b) this.parts.push(x);
25
+ return this;
26
+ }
27
+ string(s: string): this {
28
+ const b = new TextEncoder().encode(s);
29
+ return this.u32(b.length).bytes(b);
30
+ }
31
+ done(): Uint8Array {
32
+ return Uint8Array.from(this.parts);
33
+ }
34
+ }
35
+
36
+ export class Reader {
37
+ o = 0;
38
+ readonly b: Uint8Array;
39
+ constructor(b: Uint8Array) {
40
+ this.b = b;
41
+ }
42
+ uint(n: number): bigint {
43
+ if (this.o + n > this.b.length) throw new RangeError("borsh: data too short");
44
+ let v = 0n;
45
+ for (let i = n - 1; i >= 0; i--) v = (v << 8n) | BigInt(this.b[this.o + i]);
46
+ this.o += n;
47
+ return v;
48
+ }
49
+ u8 = (): number => Number(this.uint(1));
50
+ u16 = (): number => Number(this.uint(2));
51
+ u32 = (): number => Number(this.uint(4));
52
+ u64 = (): bigint => this.uint(8);
53
+ i64 = (): bigint => {
54
+ const v = this.uint(8);
55
+ return v >= 1n << 63n ? v - (1n << 64n) : v;
56
+ };
57
+ u128 = (): bigint => this.uint(16);
58
+ bool = (): boolean => this.u8() !== 0;
59
+ bytes(n: number): Uint8Array {
60
+ if (this.o + n > this.b.length) throw new RangeError("borsh: data too short");
61
+ const r = this.b.slice(this.o, this.o + n);
62
+ this.o += n;
63
+ return r;
64
+ }
65
+ pubkey = (): string => base58Encode(this.bytes(32));
66
+ }
@@ -0,0 +1,89 @@
1
+
2
+
3
+ import { MEMBERS_MAX as MAX_MEMBERS } from "../../v2/layouts.ts";
4
+ import { createLaunchInstructionV2 } from "../../v2/solana.ts";
5
+ import type { Instruction } from "../instruction.ts";
6
+ import { computeUnitLimitInstruction, computeUnitPriceInstruction } from "../instruction.ts";
7
+ import { PACKET_DATA_SIZE, compileV0Message, transactionSize } from "../tx.ts";
8
+ import type { LookupTable } from "../tx.ts";
9
+ import { createMintAccounts, teamSlotAddInstruction, TEAM_SLOT_PENDING_HANDLE, TEAM_SLOT_WALLET } from "./instructions.ts";
10
+ import { FLOOR_AMM_PROGRAM_ID, teamSlotPda } from "./program.ts";
11
+
12
+ export interface CreateSlotMember {
13
+
14
+ key: string;
15
+ kind: typeof TEAM_SLOT_WALLET | typeof TEAM_SLOT_PENDING_HANDLE;
16
+
17
+ amount: bigint;
18
+
19
+ payNow: boolean;
20
+ }
21
+
22
+ export const MAX_TX_LOCKS = 64;
23
+
24
+ export interface CreateWithSlotPlan {
25
+ instructions: Instruction[];
26
+ message: Uint8Array;
27
+ size: number;
28
+ locks: number;
29
+
30
+ fits: boolean;
31
+
32
+ transactions: { instructions: Instruction[]; message: Uint8Array; size: number }[];
33
+
34
+ teamSlot: string;
35
+ }
36
+
37
+ export function planCreateWithSlot(p: {
38
+ create: Parameters<typeof createLaunchInstructionV2>[0];
39
+ members: readonly CreateSlotMember[];
40
+ recentBlockhash: string;
41
+ lookupTables?: LookupTable[];
42
+ computeUnitLimit?: number;
43
+ microLamports?: bigint;
44
+ }): CreateWithSlotPlan {
45
+ const c = p.create;
46
+ const pid = c.programId ?? FLOOR_AMM_PROGRAM_ID;
47
+ if (p.members.length > MAX_MEMBERS) throw new RangeError(`a Team Slot has at most ${MAX_MEMBERS} members (R103)`);
48
+ const mint = createMintAccounts({ ...c, programId: pid });
49
+ const teamSlot = teamSlotPda(mint.launch, pid)[0];
50
+ const pay = { payer: c.creator, launch: mint.launch, teamSlot, quoteMint: c.quoteMint, payerQuote: c.creatorQuote, quoteVault: mint.quoteVault, quoteTokenProgram: c.quoteTokenProgram, baseMint: mint.baseMint, programId: pid };
51
+ const instructions: Instruction[] = [
52
+ ...(p.computeUnitLimit !== undefined ? [computeUnitLimitInstruction(p.computeUnitLimit)] : []),
53
+ ...(p.microLamports !== undefined ? [computeUnitPriceInstruction(p.microLamports)] : []),
54
+ createLaunchInstructionV2(c),
55
+
56
+ ...[...p.members.filter((m) => m.payNow), ...p.members.filter((m) => !m.payNow)].map((m) => teamSlotAddInstruction({ ...pay, key: m.key, kind: m.kind, amount: m.amount, payNow: m.payNow })),
57
+ ];
58
+ const compile = (ixs: Instruction[]) => {
59
+ const m = compileV0Message({ payer: c.creator, instructions: ixs, recentBlockhash: p.recentBlockhash, lookupTables: p.lookupTables });
60
+ return { instructions: ixs, message: m, size: transactionSize(m) };
61
+ };
62
+ const whole = compile(instructions);
63
+ const { message, size } = whole;
64
+ const lockSet = new Set<string>([c.creator]);
65
+ for (const ix of instructions) {
66
+ lockSet.add(ix.programAddress);
67
+ for (const a of ix.accounts) lockSet.add(a.address);
68
+ }
69
+ const fits = size <= PACKET_DATA_SIZE && lockSet.size <= MAX_TX_LOCKS;
70
+
71
+ const transactions: CreateWithSlotPlan["transactions"] = [];
72
+ if (fits) transactions.push(whole);
73
+ else {
74
+ const budget = instructions.slice(0, instructions.length - 1 - p.members.length);
75
+ const adds = instructions.slice(instructions.length - p.members.length);
76
+ let cur = instructions.slice(0, instructions.length - p.members.length);
77
+ for (const a of adds) {
78
+ const next = compile([...cur, a]);
79
+ if (next.size <= PACKET_DATA_SIZE) cur = [...cur, a];
80
+ else {
81
+ transactions.push(compile(cur));
82
+ cur = [...budget, a];
83
+ }
84
+ }
85
+ transactions.push(compile(cur));
86
+ for (const t of transactions) if (t.size > PACKET_DATA_SIZE) throw new RangeError(`a create transaction is ${t.size} B even alone: give a lookup table`);
87
+ }
88
+ return { instructions, message, size, locks: lockSet.size, fits, transactions, teamSlot };
89
+ }