@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
@@ -0,0 +1,75 @@
1
+
2
+
3
+ import { fail } from "../index.ts";
4
+ import { creatorLegs, platformLegs } from "./fees.ts";
5
+ import { U64_MAX, U128_MAX } from "./wide.ts";
6
+
7
+ export const MAX_MEMBERS = 10;
8
+ export const WEIGHT_ONE = 1_000_000_000n;
9
+
10
+ export const CREATOR_BUY_LOCK_SECS = 86_400n;
11
+
12
+ export { CREATOR_REF_BPS, TRADER_REF_BPS } from "./fees.ts";
13
+
14
+ export { platformLegs as platformLegsV2, creatorLegs as creatorLegsV2 } from "./fees.ts";
15
+
16
+ const u128 = (x: bigint): bigint => (x < 0n || x > U128_MAX ? fail("Overflow") : x);
17
+ const members = (n: number, what: string): void => {
18
+ if (n !== MAX_MEMBERS) throw new RangeError(`${what}: ${n} entries, want ${MAX_MEMBERS}`);
19
+ };
20
+
21
+ export function weightsV2(paid: readonly bigint[], bought: bigint): number[] {
22
+ members(paid.length, "paid");
23
+ const w: number[] = Array(MAX_MEMBERS).fill(0);
24
+ if (bought === 0n) return w;
25
+
26
+ const t = paid.reduce((a, p) => a + p, 0n);
27
+ if (t > U128_MAX || t > bought) fail("Overflow");
28
+ for (let i = 0; i < MAX_MEMBERS; i++) w[i] = Number(((paid[i] < bought ? paid[i] : bought) * WEIGHT_ONE) / bought);
29
+ return w;
30
+ }
31
+
32
+ export function slotWeightsV2(shares: readonly bigint[]): number[] {
33
+ members(shares.length, "shares");
34
+ const total = u128(shares.reduce((a, x) => a + x, 0n));
35
+ if (total === 0n) {
36
+ const w: number[] = Array(MAX_MEMBERS).fill(0);
37
+ w[0] = Number(WEIGHT_ONE);
38
+ return w;
39
+ }
40
+ return weightsV2(shares, total);
41
+ }
42
+
43
+ export function splitMembersV2(amount: bigint, w: readonly number[]): [bigint[], bigint] {
44
+ members(w.length, "weights");
45
+ u128(amount);
46
+ const parts: bigint[] = Array(MAX_MEMBERS).fill(0n);
47
+ let given = 0n;
48
+ for (let i = 0; i < MAX_MEMBERS; i++) {
49
+ const wi = BigInt(w[i]) < WEIGHT_ONE ? BigInt(w[i]) : WEIGHT_ONE;
50
+ let p = (amount * wi) / WEIGHT_ONE;
51
+
52
+ if (p > amount - given) p = amount - given;
53
+ parts[i] = p;
54
+ given += p;
55
+ }
56
+ return [parts, amount > given ? amount - given : 0n];
57
+ }
58
+
59
+ export function splitReleaseV2(tokens: bigint, w: readonly number[]): bigint[] {
60
+ members(w.length, "weights");
61
+ if (w.every((x) => x === 0)) {
62
+ const parts: bigint[] = Array(MAX_MEMBERS).fill(0n);
63
+ parts[0] = u128(tokens);
64
+ return parts;
65
+ }
66
+ const [parts, dust] = splitMembersV2(tokens, w);
67
+ parts[0] = u128(parts[0] + dust);
68
+ return parts;
69
+ }
70
+
71
+ export function splitTeamBuyV2(tokens: bigint, w: readonly number[], createdAt: bigint, now: bigint): bigint[] {
72
+ const due = createdAt + CREATOR_BUY_LOCK_SECS > U64_MAX ? U64_MAX : createdAt + CREATOR_BUY_LOCK_SECS;
73
+ if (now < due) fail("NotDue");
74
+ return splitReleaseV2(tokens, w);
75
+ }
@@ -0,0 +1,145 @@
1
+
2
+
3
+ import { fail } from "../index.ts";
4
+ import { U128_MAX } from "./wide.ts";
5
+ import {
6
+ Undo, ckHeld, ckMoney, cloneBook, fClaims, fOwn, feesAt, feesNow, MAX_WALK_STEPS, moneyHeld, tokensHeld, walkDownAcc, walkUpFrom,
7
+ } from "./book.ts";
8
+ import type { Book } from "./book.ts";
9
+ import { FeeAcc, LEG_BACKING, cheaper, feeTotal, netFromGross } from "./fees.ts";
10
+ import { relay } from "./relay.ts";
11
+ import type { Relay } from "./relay.ts";
12
+ import { split } from "./split.ts";
13
+ import type { Split, SplitRow } from "./split.ts";
14
+ import type { Sqrt } from "./sqrt.ts";
15
+ import { sCirc } from "./supply.ts";
16
+ import type { Supply } from "./supply.ts";
17
+
18
+ export interface BookBuy {
19
+ gross: bigint; net: bigint; refund: bigint; tokens: bigint; fees: bigint[]; fromResale: bigint; fromFirst: bigint;
20
+ steps: number; budgetHit: boolean; graduatedNow: boolean; sqrtBefore: Sqrt; sqrtAfter: Sqrt;
21
+
22
+ split: Split;
23
+
24
+ relay: Relay;
25
+ }
26
+ export interface BookSell {
27
+ tokensIn: bigint; unfilled: bigint; gross: bigint; fees: bigint[]; out: bigint; steps: number; sqrtBefore: Sqrt; sqrtAfter: Sqrt;
28
+ fromF: bigint; fromK: bigint; fromC: bigint;
29
+
30
+ relay: Relay;
31
+ }
32
+
33
+ const noSplit = (): Split => ({ dF: 0n, ckAdd: 0n, ckTake: 0n, ms: 0n, booked: [0n, 0n, 0n, 0n], sqrtFNew: 0n });
34
+ const noRelay = (): Relay => ({ nC: 0, nK: 0, laidC: 0n, laidK: 0n, atF: 0n, kept: 0 });
35
+ const add = (a: bigint, b: bigint): bigint => (a + b > U128_MAX ? fail("Overflow") : a + b);
36
+
37
+ function commit(dst: Book, src: Book): void {
38
+ Object.assign(dst, src);
39
+ }
40
+
41
+ type Side = { row: SplitRow; sup: Supply } | null;
42
+
43
+ function buyOn(book: Book, side: Side, gross: bigint, minTokens: bigint, walkSteps: number): BookBuy {
44
+ const ppm = feesNow(book);
45
+ const budget = netFromGross(gross, ppm);
46
+ if (budget === 0n) fail("NothingToDo");
47
+ const w = cloneBook(book);
48
+ const u = new Undo();
49
+
50
+ const acc = new FeeAcc(ppm);
51
+ let walked = walkUpFrom(w, budget, { money: 0n, tokens: 0n, fromResale: 0n, fromFirst: 0n, steps: 0, budgetHit: false, graduatedNow: false }, acc, walkSteps, u);
52
+ const c = cheaper(ppm, feesAt(w, w.sqrtP));
53
+ if (c.some((x, i) => x !== ppm[i]) && walked.tokens > 0n) {
54
+ const spent = walked.money + feeTotal(acc.legs());
55
+ if (spent > U128_MAX || spent > gross) fail("Overflow");
56
+ const budget2 = netFromGross(gross - spent, c);
57
+ if (budget2 > 0n) walked = walkUpFrom(w, budget2, walked, acc, walkSteps, u);
58
+ }
59
+ if (walked.tokens === 0n) fail(tokensHeld(w) === 0n ? "BookEmpty" : "NothingToDo");
60
+ if (walked.tokens < minTokens) fail("SlippageExceeded");
61
+ const fees = acc.legs();
62
+ const paid = walked.money + feeTotal(fees);
63
+ if (paid > U128_MAX || paid > gross) fail("Overflow");
64
+ w.floor = add(w.floor, fees[LEG_BACKING]);
65
+ let sp = noSplit();
66
+ let rl = noRelay();
67
+ if (w.graduated && side !== null) {
68
+
69
+ const sNew = sCirc(w, side.sup);
70
+
71
+ if (u.bought.length > 0) {
72
+ sp = split(side.row, w.ranges.slice(0, w.nRanges), {
73
+ sqrtF: w.sqrtF, sqrtP1: w.sqrtP, fTotal: fOwn(w), fClaims: fClaims(w), ck0: ckMoney(w), held: ckHeld(w), sNew,
74
+ }, u.bought);
75
+ w.floor = add(w.floor, sp.dF);
76
+ w.sqrtF = sp.sqrtFNew;
77
+ }
78
+ rl = relay(w, side.row, sp.ckAdd, sNew, sp.ckTake);
79
+ }
80
+ const r: BookBuy = {
81
+ gross, net: walked.money, refund: gross - paid, tokens: walked.tokens, fees, fromResale: walked.fromResale, fromFirst: walked.fromFirst,
82
+ steps: walked.steps, budgetHit: walked.budgetHit, graduatedNow: walked.graduatedNow, sqrtBefore: book.sqrtP, sqrtAfter: w.sqrtP,
83
+ split: sp, relay: rl,
84
+ };
85
+ commit(book, w);
86
+ return r;
87
+ }
88
+
89
+ function sellOn(book: Book, side: Side, tokens: bigint, minOut: bigint): BookSell {
90
+ if (tokens === 0n) fail("NothingToDo");
91
+ const ppm = feesNow(book);
92
+ const w = cloneBook(book);
93
+
94
+ const acc = new FeeAcc(ppm);
95
+ const walked = walkDownAcc(w, tokens, acc);
96
+ const fees = acc.legs();
97
+ const total = feeTotal(fees);
98
+ if (walked.tokens === 0n || walked.money <= total) fail(walked.money === 0n && moneyHeld(w) === 0n ? "BookEmpty" : "NothingToDo");
99
+ const out = walked.money - total;
100
+ if (out < minOut) fail("SlippageExceeded");
101
+ w.floor = add(w.floor, fees[LEG_BACKING]);
102
+
103
+ const rl = w.graduated && side !== null ? relay(w, side.row, 0n, sCirc(w, side.sup)) : noRelay();
104
+ const r: BookSell = {
105
+ tokensIn: tokens, unfilled: tokens - walked.tokens, gross: walked.money, fees, out, steps: walked.steps, sqrtBefore: book.sqrtP, sqrtAfter: w.sqrtP,
106
+ fromF: walked.fromF, fromK: walked.fromK, fromC: walked.fromC, relay: rl,
107
+ };
108
+ commit(book, w);
109
+ return r;
110
+ }
111
+
112
+ export function buy(book: Book, row: SplitRow, sup: Supply, gross: bigint, minTokens: bigint, opts: { walkSteps?: number } = {}): BookBuy {
113
+ return buyOn(book, { row, sup }, gross, minTokens, opts.walkSteps ?? MAX_WALK_STEPS);
114
+ }
115
+
116
+ export function sell(book: Book, row: SplitRow, sup: Supply, tokens: bigint, minOut: bigint): BookSell {
117
+ return sellOn(book, { row, sup }, tokens, minOut);
118
+ }
119
+
120
+ export const quoteBuy = (book: Book, row: SplitRow, sup: Supply, gross: bigint, walkSteps: number = MAX_WALK_STEPS): BookBuy =>
121
+ buy(cloneBook(book), row, sup, gross, 0n, { walkSteps });
122
+ export const quoteSell = (book: Book, row: SplitRow, sup: Supply, tokens: bigint): BookSell => sell(cloneBook(book), row, sup, tokens, 0n);
123
+
124
+ export function buyMinTokens(b: Book, row: SplitRow, sup: Supply, gross: bigint, slippageBps: number, walkSteps: number = MAX_WALK_STEPS): bigint {
125
+ const less = buyLessIn(gross, slippageBps);
126
+
127
+ return slippageBps === 10_000 ? 0n : buy(cloneBook(b), row, sup, less, 0n, { walkSteps }).tokens;
128
+ }
129
+
130
+ export function buyLessIn(gross: bigint, slippageBps: number): bigint {
131
+
132
+ if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps > 10_000) fail("VaultShareOutOfRange");
133
+ return (gross * BigInt(10_000 - slippageBps)) / 10_000n;
134
+ }
135
+
136
+ export function bookBuy(book: Book, gross: bigint, minTokens: bigint, walkSteps: number = MAX_WALK_STEPS): BookBuy {
137
+ return buyOn(book, null, gross, minTokens, walkSteps);
138
+ }
139
+
140
+ export function bookSell(book: Book, tokens: bigint, minOut: bigint): BookSell {
141
+ return sellOn(book, null, tokens, minOut);
142
+ }
143
+
144
+ export const quoteBookBuy = (book: Book, gross: bigint, walkSteps: number = MAX_WALK_STEPS): BookBuy => bookBuy(cloneBook(book), gross, 0n, walkSteps);
145
+ export const quoteBookSell = (book: Book, tokens: bigint): BookSell => bookSell(cloneBook(book), tokens, 0n);
@@ -0,0 +1,52 @@
1
+
2
+
3
+ export type Round = "down" | "up";
4
+ export const DOWN: Round = "down";
5
+ export const UP: Round = "up";
6
+
7
+ export const U64_MAX = (1n << 64n) - 1n;
8
+ export const U128_MAX = (1n << 128n) - 1n;
9
+ const W3_LIMIT = 1n << 384n;
10
+ export const U256_LIMIT = 1n << 256n;
11
+
12
+ export function shlW(w: bigint, k: number): bigint | null {
13
+ const v = w << BigInt(k);
14
+ return v >= W3_LIMIT ? null : v;
15
+ }
16
+
17
+ export function shrW(w: bigint, k: number, r: Round): bigint {
18
+ const kk = BigInt(k);
19
+ const q = w >> kk;
20
+ return r === UP && q << kk !== w ? q + 1n : q;
21
+ }
22
+
23
+ export function divW(w: bigint, d: bigint, r: Round): bigint | null {
24
+ if (d === 0n) return null;
25
+ const q = w / d;
26
+ if (q >= U256_LIMIT) return null;
27
+ if (r === UP && q * d !== w) return q + 1n >= U256_LIMIT ? null : q + 1n;
28
+ return q;
29
+ }
30
+
31
+ export const toU128 = (x: bigint | null): bigint | null => (x === null || x > U128_MAX ? null : x);
32
+ export const wU128 = toU128;
33
+
34
+ export const mulDiv = (a: bigint, b: bigint, d: bigint, r: Round): bigint | null => toU128(divW(a * b, d, r));
35
+
36
+ export const mulShr = (a: bigint, b: bigint, k: number, r: Round): bigint | null => toU128(shrW(a * b, k, r));
37
+
38
+ export function shlDiv(x: bigint, k: number, d: bigint, r: Round): bigint | null {
39
+ const s = shlW(x, k);
40
+ return s === null ? null : divW(s, d, r);
41
+ }
42
+
43
+ export function isqrt(n: bigint): bigint {
44
+ if (n < 0n) throw new RangeError("isqrt of a negative");
45
+ if (n < 2n) return n;
46
+ let x = 1n << BigInt((n.toString(2).length + 1) >> 1);
47
+ for (;;) {
48
+ const y = (x + n / x) >> 1n;
49
+ if (y >= x) return x;
50
+ x = y;
51
+ }
52
+ }
package/src/quote.ts ADDED
@@ -0,0 +1,6 @@
1
+
2
+
3
+ export { FloorError, FloorQuoteError, FLOOR_ERROR_CODES, decodeProgramError, decodeSolanaProgramError, decodeEvmProgramError, isFloorError } from "./errors.ts";
4
+ export type { FloorErrorCode, FloorErrorSource, QuoteErrorCode } from "./errors.ts";
5
+ export { createFloorClient, DEFAULT_SLIPPAGE_BPS } from "./client/index.ts";
6
+ export type * from "./client/types.ts";
@@ -0,0 +1,28 @@
1
+
2
+
3
+ export const REGISTRY_PRICE_MAX_AGE_S = 86_400n;
4
+
5
+ export interface RegistryPrice {
6
+ usdCentsX64: bigint;
7
+ updatedAt: bigint;
8
+ }
9
+
10
+ export class StaleRegistryPriceError extends Error {
11
+ readonly ageS: bigint;
12
+ constructor(ageS: bigint) {
13
+ super(`the quote's registry price is ${ageS} s old; a create takes one at most ${REGISTRY_PRICE_MAX_AGE_S} s (24 h) old`);
14
+ this.name = "RegistryPriceStale";
15
+ this.ageS = ageS;
16
+ }
17
+ }
18
+
19
+ export const registryPriceAge = (updatedAt: bigint, now: bigint): bigint => (now > updatedAt ? now - updatedAt : 0n);
20
+
21
+ export const registryPriceFresh = (updatedAt: bigint, now: bigint): boolean => registryPriceAge(updatedAt, now) <= REGISTRY_PRICE_MAX_AGE_S;
22
+
23
+ export function freshRegistryPrice(row: RegistryPrice, now: bigint): bigint {
24
+ if (row.usdCentsX64 <= 0n) throw new RangeError("the registry row has no price");
25
+ const age = registryPriceAge(row.updatedAt, now);
26
+ if (age > REGISTRY_PRICE_MAX_AGE_S) throw new StaleRegistryPriceError(age);
27
+ return row.usdCentsX64;
28
+ }
@@ -0,0 +1,71 @@
1
+
2
+
3
+ import { base58Decode } from "../codec.ts";
4
+ import type { Instruction } from "../solana/instruction.ts";
5
+ import type { EdgeLeg } from "./edge.ts";
6
+
7
+ export interface JupiterInstruction {
8
+ programId: string;
9
+ accounts: { pubkey: string; isSigner: boolean; isWritable: boolean }[];
10
+
11
+ data: string;
12
+ }
13
+
14
+ export interface JupiterSwapInstructions {
15
+ computeBudgetInstructions?: JupiterInstruction[];
16
+ setupInstructions?: JupiterInstruction[];
17
+ swapInstruction: JupiterInstruction;
18
+ cleanupInstruction?: JupiterInstruction | null;
19
+ otherInstructions?: JupiterInstruction[];
20
+ addressLookupTableAddresses?: string[];
21
+ }
22
+
23
+ export interface JupiterQuote {
24
+ inputMint: string;
25
+ outputMint: string;
26
+ inAmount: string;
27
+ outAmount: string;
28
+
29
+ otherAmountThreshold: string;
30
+ slippageBps: number;
31
+ swapMode?: string;
32
+ }
33
+
34
+ export function jupiterSwapInstructionsBody(p: { quote: JupiterQuote; trader: string; destinationTokenAccount?: string }): string {
35
+ return JSON.stringify({ quoteResponse: p.quote, userPublicKey: p.trader, wrapAndUnwrapSol: true, dynamicComputeUnitLimit: true, ...(p.destinationTokenAccount ? { destinationTokenAccount: p.destinationTokenAccount } : {}) });
36
+ }
37
+
38
+ function base64Decode(s: string): Uint8Array {
39
+ const b = atob(s);
40
+ const out = new Uint8Array(b.length);
41
+ for (let i = 0; i < b.length; i++) out[i] = b.charCodeAt(i);
42
+ return out;
43
+ }
44
+
45
+ export function fromJupiter(j: JupiterInstruction): Instruction {
46
+ base58Decode(j.programId);
47
+ return {
48
+ programAddress: j.programId,
49
+ accounts: j.accounts.map((a) => ({ address: a.pubkey, role: ((a.isSigner ? 2 : 0) | (a.isWritable ? 1 : 0)) as 0 | 1 | 2 | 3 })),
50
+ data: base64Decode(j.data),
51
+ };
52
+ }
53
+
54
+ export function jupiterLeg(j: JupiterSwapInstructions): Instruction[] {
55
+ return [...(j.setupInstructions ?? []), j.swapInstruction, ...(j.cleanupInstruction ? [j.cleanupInstruction] : []), ...(j.otherInstructions ?? [])].map(fromJupiter);
56
+ }
57
+
58
+ export function jupiterEdgeLeg(j: JupiterSwapInstructions): EdgeLeg {
59
+ const jb = (j.computeBudgetInstructions ?? []).map(fromJupiter);
60
+ const limit = jb.find((ix) => ix.data[0] === 2 && ix.data.length >= 5);
61
+ const price = jb.find((ix) => ix.data[0] === 3 && ix.data.length >= 9);
62
+ const dv = (ix: Instruction): DataView => new DataView(ix.data.buffer, ix.data.byteOffset);
63
+ return {
64
+ setup: (j.setupInstructions ?? []).map(fromJupiter),
65
+ swap: [fromJupiter(j.swapInstruction)],
66
+ cleanup: [...(j.cleanupInstruction ? [j.cleanupInstruction] : []), ...(j.otherInstructions ?? [])].map(fromJupiter),
67
+ lookupTableAddresses: [...(j.addressLookupTableAddresses ?? [])],
68
+ ...(limit ? { computeUnits: dv(limit).getUint32(1, true) } : {}),
69
+ ...(price ? { computeUnitPrice: dv(price).getBigUint64(1, true) } : {}),
70
+ };
71
+ }
@@ -0,0 +1,22 @@
1
+
2
+
3
+ import { COMPUTE_BUDGET_PROGRAM_ID } from "../solana/instruction.ts";
4
+ import type { Instruction } from "../solana/instruction.ts";
5
+
6
+ export interface EdgeLeg {
7
+ setup: Instruction[];
8
+ swap: Instruction[];
9
+ cleanup: Instruction[];
10
+
11
+ lookupTableAddresses: string[];
12
+ computeUnits?: number;
13
+ computeUnitPrice?: bigint;
14
+ }
15
+
16
+ export const EDGE_UNKNOWN_CU = 400_000;
17
+
18
+ export function edgeLegInstructions(leg: EdgeLeg): Instruction[] {
19
+ const ixs = [...leg.setup, ...leg.swap, ...leg.cleanup];
20
+ for (const ix of ixs) if (ix.programAddress === COMPUTE_BUDGET_PROGRAM_ID) throw new RangeError("a compute budget instruction outside the budget slot");
21
+ return ixs;
22
+ }
@@ -0,0 +1,77 @@
1
+
2
+
3
+ export const SOL_NATIVE = "SOL";
4
+
5
+ export const EVM_NATIVE = "0x0000000000000000000000000000000000000000";
6
+
7
+ export interface Pool {
8
+ chain: "solana" | "evm";
9
+
10
+ token: string;
11
+
12
+ quote: string;
13
+
14
+ quoteTokenProgram?: string;
15
+
16
+ launchId?: bigint;
17
+
18
+ state: unknown;
19
+ symbol: string;
20
+
21
+ referred?: boolean;
22
+ linked?: boolean;
23
+ snipeSpan?: boolean;
24
+ }
25
+
26
+ export interface QuoteGraph {
27
+ pools: Map<string, Pool>;
28
+ edge: Set<string>;
29
+ }
30
+
31
+ export type NoRouteReason = "Same" | "NoFloorHop" | "QuoteCycle" | "Mixed" | "TooManyHops";
32
+
33
+ export class NoRouteError extends Error {
34
+ readonly reason: NoRouteReason;
35
+ constructor(reason: NoRouteReason, detail: string) {
36
+ super(`NoRoute (${reason}): ${detail}`);
37
+ this.name = "NoRouteError";
38
+ this.reason = reason;
39
+ }
40
+ }
41
+
42
+ export const coinKey = (a: string): string => (a.startsWith("0x") ? a.toLowerCase() : a);
43
+
44
+ export const MAX_QUOTE_CHAIN = 8;
45
+
46
+ export async function quoteGraph(p: { chain: "solana" | "evm"; tokens: string[]; edge: string[]; readPool: (token: string) => Promise<Pool | null> }): Promise<QuoteGraph> {
47
+ const g: QuoteGraph = { pools: new Map(), edge: new Set(p.edge.map(coinKey)) };
48
+ const seen = new Set<string>();
49
+ for (const t of p.tokens) {
50
+ let coin = t;
51
+ for (let depth = 0; ; depth++) {
52
+ const k = coinKey(coin);
53
+ if (g.edge.has(k) || seen.has(k)) break;
54
+ if (depth > MAX_QUOTE_CHAIN) throw new NoRouteError("QuoteCycle", `${t}'s quote chain passes ${MAX_QUOTE_CHAIN} pools`);
55
+ seen.add(k);
56
+ const pool = await p.readPool(coin);
57
+ if (pool === null) break;
58
+ if (pool.chain !== p.chain) throw new NoRouteError("Mixed", `${coin} is a ${pool.chain} launch on a ${p.chain} graph`);
59
+ g.pools.set(k, pool);
60
+ coin = pool.quote;
61
+ }
62
+ }
63
+ return g;
64
+ }
65
+
66
+ export function quoteChain(g: QuoteGraph, token: string): { pools: Pool[]; base: string } {
67
+ const pools: Pool[] = [];
68
+ let coin = token;
69
+ for (;;) {
70
+ const k = coinKey(coin);
71
+ const pool = g.edge.has(k) ? undefined : g.pools.get(k);
72
+ if (!pool) return { pools, base: coin };
73
+ if (pools.length >= MAX_QUOTE_CHAIN || pools.includes(pool)) throw new NoRouteError("QuoteCycle", `${token}'s quote chain does not end`);
74
+ pools.push(pool);
75
+ coin = pool.quote;
76
+ }
77
+ }
@@ -0,0 +1,84 @@
1
+
2
+
3
+ import { WSOL_MINT } from "../solana/pda.ts";
4
+ import { EVM_NATIVE, NoRouteError, SOL_NATIVE, coinKey, quoteChain } from "./graph.ts";
5
+ import type { Pool, QuoteGraph } from "./graph.ts";
6
+
7
+ export type Hop =
8
+
9
+ | { kind: "edge"; from: string; to: string }
10
+
11
+ | { kind: "buy"; pool: Pool }
12
+
13
+ | { kind: "sell"; pool: Pool };
14
+
15
+ export interface RoutePath {
16
+
17
+ chain: "solana" | "evm";
18
+ from: string;
19
+ to: string;
20
+ hops: Hop[];
21
+ }
22
+
23
+ export function findRoute(g: QuoteGraph, from: string, to: string): RoutePath {
24
+ if (coinKey(from) === coinKey(to)) throw new NoRouteError("Same", `${from} → itself`);
25
+ const a = quoteChain(g, from);
26
+ const b = quoteChain(g, to);
27
+ const chain = (a.pools[0] ?? b.pools[0])?.chain;
28
+ if (chain === undefined) throw new NoRouteError("NoFloorHop", `${from} → ${to} crosses no FLOOR pool`);
29
+ if ([...a.pools, ...b.pools].some((x) => x.chain !== chain)) throw new NoRouteError("Mixed", `${from} → ${to} mixes chains`);
30
+
31
+ const coinsA = [from, ...a.pools.map((x) => x.quote)].map(coinKey);
32
+ const coinsB = [to, ...b.pools.map((x) => x.quote)].map(coinKey);
33
+ let ia = -1;
34
+ let ib = -1;
35
+ for (let i = 0; i < coinsA.length && ia < 0; i++) {
36
+ const j = coinsB.indexOf(coinsA[i]);
37
+ if (j >= 0) [ia, ib] = [i, j];
38
+ }
39
+ const hops: Hop[] = [];
40
+ if (ia >= 0) {
41
+ for (const pool of a.pools.slice(0, ia)) hops.push({ kind: "sell", pool });
42
+ for (const pool of b.pools.slice(0, ib).reverse()) hops.push({ kind: "buy", pool });
43
+ } else {
44
+ for (const pool of a.pools) hops.push({ kind: "sell", pool });
45
+ hops.push({ kind: "edge", from: a.base, to: b.base });
46
+ for (const pool of [...b.pools].reverse()) hops.push({ kind: "buy", pool });
47
+ }
48
+ if (!hops.some((h) => h.kind !== "edge")) throw new NoRouteError("NoFloorHop", `${from} → ${to} crosses no FLOOR pool`);
49
+ return { chain, from, to, hops };
50
+ }
51
+
52
+ export function isWrapHop(h: Hop): boolean {
53
+ return h.kind === "edge" && ((h.from === SOL_NATIVE && h.to === WSOL_MINT) || (h.from === WSOL_MINT && h.to === SOL_NATIVE));
54
+ }
55
+
56
+ export function hopIn(h: Hop): string {
57
+ return h.kind === "edge" ? h.from : h.kind === "buy" ? h.pool.quote : h.pool.token;
58
+ }
59
+ export function hopOut(h: Hop): string {
60
+ return h.kind === "edge" ? h.to : h.kind === "buy" ? h.pool.token : h.pool.quote;
61
+ }
62
+
63
+ const USDC_SOLANA = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
64
+ const KNOWN: Record<string, string> = { [SOL_NATIVE]: "SOL", [WSOL_MINT]: "wSOL", [USDC_SOLANA]: "USDC" };
65
+
66
+ export function describeRoute(path: RoutePath, names: Record<string, string> = {}, edgeName?: string): string {
67
+ const byKey = new Map(Object.entries(names).map(([k, v]) => [coinKey(k), v]));
68
+ const pools = new Map(path.hops.filter((h) => h.kind !== "edge").map((h) => [coinKey((h as { pool: Pool }).pool.token), (h as { pool: Pool }).pool]));
69
+ const name = (c: string): string => {
70
+ const n = byKey.get(coinKey(c));
71
+ if (n !== undefined) return n;
72
+ const p = pools.get(coinKey(c));
73
+ if (p) return p.symbol.startsWith("$") ? p.symbol : `$${p.symbol}`;
74
+ if (KNOWN[c]) return KNOWN[c];
75
+ if (path.chain === "evm" && coinKey(c) === EVM_NATIVE) return "native";
76
+ return c.length > 10 ? `${c.slice(0, 4)}…${c.slice(-4)}` : c;
77
+ };
78
+ let s = name(path.from);
79
+ for (const h of path.hops) {
80
+ s += ` → ${name(hopOut(h))}`;
81
+ if (h.kind === "edge") s += isWrapHop(h) ? (h.from === SOL_NATIVE ? " (wrap)" : " (unwrap)") : ` (${edgeName ?? (path.chain === "solana" ? "Jupiter" : "DEX")})`;
82
+ }
83
+ return s;
84
+ }
@@ -0,0 +1,46 @@
1
+
2
+
3
+ import { hopIn } from "./path.ts";
4
+ import type { Hop, RoutePath } from "./path.ts";
5
+
6
+ export interface EdgeQuote {
7
+ inAmount: bigint;
8
+ outAmount: bigint;
9
+
10
+ minOut: bigint;
11
+
12
+ raw: unknown;
13
+ }
14
+ export type EdgeQuoter = (req: { from: string; to: string; amountIn: bigint; slippageBps: number }) => Promise<EdgeQuote>;
15
+
16
+ export type HopStage = "window" | "schedule" | "budget" | "after-end" | "sell" | "edge" | "wrap";
17
+
18
+ export interface HopQuote {
19
+ hop: Hop;
20
+ amountIn: bigint;
21
+ amountOut: bigint;
22
+ minOut: bigint;
23
+ computeUnits?: number;
24
+ gas?: bigint;
25
+
26
+ stage?: HopStage;
27
+
28
+ impactBps?: number;
29
+
30
+ edge?: EdgeQuote;
31
+ }
32
+
33
+ export interface RouteQuote {
34
+ path: RoutePath;
35
+ amountIn: bigint;
36
+ amountOut: bigint;
37
+ minOut: bigint;
38
+ hops: HopQuote[];
39
+ slippageBps: number;
40
+
41
+ surplus?: { coin: string; expected: bigint };
42
+ }
43
+
44
+ export function routeInputs(q: RouteQuote): string[] {
45
+ return q.path.hops.map(hopIn);
46
+ }
@@ -0,0 +1,36 @@
1
+
2
+
3
+ import { WSOL_MINT } from "./solana/pda.ts";
4
+ import { SOL_NATIVE } from "./route/graph.ts";
5
+ import { isWrapHop } from "./route/path.ts";
6
+ import type { EdgeQuoter, RouteQuote } from "./route/quote.ts";
7
+ import { jupiterSwapInstructionsBody } from "./route/edge-jupiter.ts";
8
+ import type { JupiterQuote } from "./route/edge-jupiter.ts";
9
+
10
+ export const JUPITER_API = "https://lite-api.jup.ag/swap/v1";
11
+
12
+ export function jupiterQuoteUrl(p: { quoteMint: string; lamports: bigint; slippageBps: number; api?: string; inputMint?: string }): string {
13
+ if (p.lamports <= 0n) throw new RangeError("lamports must be > 0");
14
+ if (!Number.isInteger(p.slippageBps) || p.slippageBps < 0 || p.slippageBps > 10_000) throw new RangeError("slippageBps in 0..10,000");
15
+ const q = new URLSearchParams({ inputMint: p.inputMint ?? WSOL_MINT, outputMint: p.quoteMint, amount: p.lamports.toString(), slippageBps: String(p.slippageBps), swapMode: "ExactIn" });
16
+ return `${p.api ?? JUPITER_API}/quote?${q.toString()}`;
17
+ }
18
+
19
+ const jupMint = (c: string): string => (c === SOL_NATIVE ? WSOL_MINT : c);
20
+
21
+ export function jupiterEdgeQuoter(fetchJson: (url: string) => Promise<unknown>, opts: { api?: string } = {}): EdgeQuoter {
22
+ return async ({ from, to, amountIn, slippageBps }) => {
23
+ const raw = (await fetchJson(jupiterQuoteUrl({ inputMint: jupMint(from), quoteMint: jupMint(to), lamports: amountIn, slippageBps, api: opts.api }))) as JupiterQuote;
24
+ return { inAmount: BigInt(raw.inAmount), outAmount: BigInt(raw.outAmount), minOut: BigInt(raw.otherAmountThreshold), raw };
25
+ };
26
+ }
27
+
28
+ export function jupiterSwapRequests(q: RouteQuote, trader: string, opts: { api?: string } = {}): { hop: number; url: string; body: string }[] {
29
+ const out: { hop: number; url: string; body: string }[] = [];
30
+ q.hops.forEach((h, i) => {
31
+ if (h.hop.kind !== "edge" || isWrapHop(h.hop)) return;
32
+ if (!h.edge) throw new RangeError(`hop ${i} has no edge quote`);
33
+ out.push({ hop: i, url: `${opts.api ?? JUPITER_API}/swap-instructions`, body: jupiterSwapInstructionsBody({ quote: h.edge.raw as JupiterQuote, trader }) });
34
+ });
35
+ return out;
36
+ }
package/src/route.ts ADDED
@@ -0,0 +1,8 @@
1
+
2
+
3
+ export * from "./route/graph.ts";
4
+ export * from "./route/path.ts";
5
+ export * from "./route/quote.ts";
6
+ export * from "./route/edge.ts";
7
+ export * from "./route/edge-jupiter.ts";
8
+ export * from "./route-jupiter.ts";