@floorlaunchpad/sdk 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floorlaunchpad/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "The FLOOR Program in TypeScript: the math, the quoter, decoders, PDAs and instruction builders for Solana and EVM",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -106,6 +106,7 @@ export const EVM_ERRORS: readonly ProgramErrorRow[] = [
106
106
  { chain: "evm", name: "PresetDisabled", message: "PresetDisabled", code: null, selector: "0x5518d9cd", signature: "PresetDisabled()" },
107
107
  { chain: "evm", name: "PresetIdNotNext", message: "PresetIdNotNext", code: null, selector: "0x9b5a5243", signature: "PresetIdNotNext()" },
108
108
  { chain: "evm", name: "PresetInvalid", message: "PresetInvalid", code: null, selector: "0x46f63096", signature: "PresetInvalid()" },
109
+ { chain: "evm", name: "PriceOrder", message: "PriceOrder", code: null, selector: "0x6b2c148b", signature: "PriceOrder()" },
109
110
  { chain: "evm", name: "QuoteDisabled", message: "QuoteDisabled", code: null, selector: "0x31ccdc5d", signature: "QuoteDisabled()" },
110
111
  { chain: "evm", name: "QuoteListed", message: "QuoteListed", code: null, selector: "0xe6faf0c2", signature: "QuoteListed()" },
111
112
  { chain: "evm", name: "QuoteNotListed", message: "QuoteNotListed", code: null, selector: "0x06ff137a", signature: "QuoteNotListed()" },
@@ -120,6 +121,7 @@ export const EVM_ERRORS: readonly ProgramErrorRow[] = [
120
121
  { chain: "evm", name: "SafeERC20FailedOperation", message: "SafeERC20FailedOperation", code: null, selector: "0x5274afe7", signature: "SafeERC20FailedOperation(address)" },
121
122
  { chain: "evm", name: "SellTooLarge", message: "SellTooLarge", code: null, selector: "0x8e4d208f", signature: "SellTooLarge()" },
122
123
  { chain: "evm", name: "SlippageExceeded", message: "SlippageExceeded", code: null, selector: "0x8199f5f3", signature: "SlippageExceeded()" },
124
+ { chain: "evm", name: "SqrtRange", message: "SqrtRange", code: null, selector: "0x1e523888", signature: "SqrtRange()" },
123
125
  { chain: "evm", name: "StringsInsufficientHexLength", message: "StringsInsufficientHexLength", code: null, selector: "0xe22e27eb", signature: "StringsInsufficientHexLength(uint256,uint256)" },
124
126
  { chain: "evm", name: "SwapDataNotEmpty", message: "SwapDataNotEmpty", code: null, selector: "0x8821f518", signature: "SwapDataNotEmpty()" },
125
127
  { chain: "evm", name: "SwapFailed", message: "SwapFailed", code: null, selector: "0xff9fa595", signature: "SwapFailed(bytes)" },
@@ -135,5 +137,8 @@ export const EVM_ERRORS: readonly ProgramErrorRow[] = [
135
137
  { chain: "evm", name: "UnknownLaunch", message: "UnknownLaunch", code: null, selector: "0xf6806bf8", signature: "UnknownLaunch()" },
136
138
  { chain: "evm", name: "UUPSUnauthorizedCallContext", message: "UUPSUnauthorizedCallContext", code: null, selector: "0xe07c8dba", signature: "UUPSUnauthorizedCallContext()" },
137
139
  { chain: "evm", name: "UUPSUnsupportedProxiableUUID", message: "UUPSUnsupportedProxiableUUID", code: null, selector: "0xaa1d49a4", signature: "UUPSUnsupportedProxiableUUID(bytes32)" },
140
+ { chain: "evm", name: "VaultShareOutOfRange", message: "VaultShareOutOfRange", code: null, selector: "0xdb8df2d8", signature: "VaultShareOutOfRange()" },
141
+ { chain: "evm", name: "Zero", message: "Zero", code: null, selector: "0xf4560403", signature: "Zero()" },
138
142
  { chain: "evm", name: "ZeroAddress", message: "ZeroAddress", code: null, selector: "0xd92e233d", signature: "ZeroAddress()" },
143
+ { chain: "evm", name: "ZeroLiquidity", message: "ZeroLiquidity", code: null, selector: "0x10074548", signature: "ZeroLiquidity()" },
139
144
  ];
@@ -228,19 +228,24 @@ export function createSolanaClient(opts: FloorClientOptions<"solana">): FloorCli
228
228
 
229
229
  claim: (p: ClaimParams<"solana">): Promise<SolanaTx> => guard(async () => {
230
230
  const tok = (p.types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
231
- const launches: ClaimLaunchV2[] = [];
232
231
  let qtp: string | null = null;
233
232
  let qIsLaunch = false;
234
- for (const mint of p.launches) {
233
+
234
+ const read = await Promise.all(p.launches.map(async (mint) => {
235
235
  const { address, l } = await launchOf(mint);
236
236
  if (l.quoteMint !== p.quote) throw bad(`launch ${mint} trades in ${l.quoteMint}, not ${p.quote}`);
237
- qtp = l.quoteTokenProgram;
238
- qIsLaunch = await quoteIsLaunchOf(l);
239
237
  const slot = teamSlotPda(address, pid)[0];
240
- launches.push({
241
- launch: address, quoteVault: l.quoteVault, teamSlot: (await get(slot)) !== null ? slot : null, baseMint: l.baseMint,
242
- ...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
243
- });
238
+ const [isLaunch, slotAcc] = await Promise.all([quoteIsLaunchOf(l), get(slot)]);
239
+ return { mint, address, l, slot, isLaunch, slotAcc };
240
+ }));
241
+ const launches: ClaimLaunchV2[] = read.map(({ address, l, slot, slotAcc }) => ({
242
+ launch: address, quoteVault: l.quoteVault, teamSlot: slotAcc !== null ? slot : null, baseMint: l.baseMint,
243
+ ...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
244
+ }));
245
+ const last = read.at(-1);
246
+ if (last !== undefined) {
247
+ qtp = last.l.quoteTokenProgram;
248
+ qIsLaunch = last.isLaunch;
244
249
  }
245
250
  if (qtp === null) {
246
251
  const m = await get(p.quote);
@@ -27120,7 +27120,7 @@ export const CHAIN_ROWS = [
27120
27120
  "name": "elysium",
27121
27121
  "label": "Elysium",
27122
27122
  "family": "evm",
27123
- "v2DayOne": false,
27123
+ "v2DayOne": true,
27124
27124
  "chainId": 99901,
27125
27125
  "native": "HYPE",
27126
27126
  "nativeName": "Hype",
@@ -115,7 +115,7 @@ export const CHAIN_REGISTRY = [
115
115
  "slug": "elysium",
116
116
  "label": "Elysium",
117
117
  "family": "evm",
118
- "v2DayOne": false,
118
+ "v2DayOne": true,
119
119
  "chainId": 99901,
120
120
  "soakChainId": 99801,
121
121
  "native": {
package/src/evm/chains.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { bytesToHex, checksumAddress, create2Address, encodeAbi, hexToBytes } from "./abi.ts";
4
4
  import { keccak256 } from "./keccak.ts";
5
- import type { ZapFamily } from "./zap.ts";
5
+ import type { ZapFamily, ZapUrFork } from "./zap.ts";
6
6
  import { CHAIN_REGISTRY, EVM_CHAIN_SLUGS } from "../config/registry.gen.ts";
7
7
 
8
8
  export type ChainKey = (typeof EVM_CHAIN_SLUGS)[number];
@@ -18,6 +18,12 @@ export interface ZapRouter {
18
18
  optional: boolean;
19
19
 
20
20
  forkEncoding?: boolean;
21
+
22
+ urFork?: ZapUrFork;
23
+
24
+ zap: string | null;
25
+
26
+ floorRouter: string;
21
27
  }
22
28
 
23
29
  export interface EvmChain {
@@ -42,79 +48,140 @@ function strict(a: string): string {
42
48
  return c;
43
49
  }
44
50
 
45
- const r = (slot: string, amm: string, router: string, family: ZapFamily, confidence: ZapRouter["confidence"], optional = false, forkEncoding = false): ZapRouter => ({
51
+ const UR_FORK_OF_SLOT: Readonly<Record<string, ZapUrFork>> = { "aerodrome-ur": "aerodrome", "pancake-ur": "pancake", "ramses-ur": "ramses" };
52
+ function urForkOf(slot: string): ZapUrFork {
53
+ const f = UR_FORK_OF_SLOT[slot];
54
+ if (!f) throw new RangeError(`the UR fork row ${slot} names no fork`);
55
+ return f;
56
+ }
57
+
58
+ type ZapRouterSpec = Omit<ZapRouter, "zap" | "floorRouter">;
59
+
60
+ const r = (slot: string, amm: string, router: string, family: ZapFamily, confidence: ZapRouter["confidence"], optional = false, forkEncoding = false): ZapRouterSpec => ({
46
61
  slot,
47
62
  amm,
48
63
  router: strict(router),
49
64
  family,
50
65
  confidence,
51
66
  optional,
52
- ...(forkEncoding ? { forkEncoding } : {}),
67
+ ...(forkEncoding ? { forkEncoding, urFork: urForkOf(slot) } : {}),
53
68
  });
54
69
 
70
+ export const FLOOR_ZAP_ADDRESSES: Readonly<Record<ChainKey, Readonly<Record<string, string>>>> = {
71
+ ethereum: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
72
+ base: {
73
+ "aerodrome-ur": strict("0xD8329A195F26c27A911B5CE697B11947984dc0d1"),
74
+ "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
75
+ "pancake-ur": strict("0xE4335AaC829a788bb6988A372edfe3Cda41B0931"),
76
+ },
77
+ bsc: {
78
+ "pancake-ur": strict("0xE4335AaC829a788bb6988A372edfe3Cda41B0931"),
79
+ "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
80
+ },
81
+ arbitrum: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
82
+ hyperevm: {
83
+ prjx: strict("0x02E658B2B205F76850Cf6d584477A58cD797e46a"),
84
+ nest: strict("0x93aC608AA016271BBB92924C3838a0b550c34ce1"),
85
+ "ramses-ur": strict("0x4b22d4b3F104D76aB92A2CA4E5E4A08A27F18f52"),
86
+ hyperswap: strict("0x782DB7e687E16Bfe00C9a0CE41A76A7cC507566F"),
87
+ },
88
+ robinhood: {
89
+ "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
90
+ "ramses-ur": strict("0x4b22d4b3F104D76aB92A2CA4E5E4A08A27F18f52"),
91
+ },
92
+ arc: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
93
+ elysium: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
94
+ };
95
+
96
+ export const FLOOR_ROUTER_DEPLOYER = strict("0x3e70158e54E91d2984c0F3B66ce2cE730d1E0e11");
97
+
98
+ const ROUTER_PROXY_INITCODE = "0x67363d3d37363d34f03d5260086018f3";
99
+
100
+ function slotWord(slot: string): Uint8Array {
101
+ const b = new TextEncoder().encode(slot);
102
+ if (b.length === 0 || b.length > 32) throw new RangeError(`a router slot is 1..32 bytes: ${JSON.stringify(slot)}`);
103
+ const w = new Uint8Array(32);
104
+ w.set(b);
105
+ return w;
106
+ }
107
+
108
+ export function floorRouterAddress(slot: string, deployer: string = FLOOR_ROUTER_DEPLOYER): string {
109
+ const s = keccak256(encodeAbi(["string", "bytes32"], ["floor-router.v1.FloorRouter", bytesToHex(slotWord(slot))]));
110
+ const proxy = create2Address({ deployer, salt: s, initCode: ROUTER_PROXY_INITCODE });
111
+
112
+ return checksumAddress(bytesToHex(keccak256(hexToBytes("0xd694" + proxy.slice(2) + "01")).slice(12)));
113
+ }
114
+
115
+ function withBookedZaps(key: ChainKey, rows: readonly ZapRouterSpec[]): ZapRouter[] {
116
+ const book = FLOOR_ZAP_ADDRESSES[key];
117
+ return rows.map((row) => ({ ...row, zap: book[row.slot] ?? null, floorRouter: floorRouterAddress(row.slot) }));
118
+ }
119
+
55
120
  const UNISWAP_UR = "uniswap-ur";
56
121
 
57
122
  const ROUTES: Record<ChainKey, Omit<EvmChain, "key" | "chainId" | "name" | "nativeSymbol">> = {
58
123
  ethereum: {
59
124
  wrappedNative: strict("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
60
- zapRouters: [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x4C82D1fBFe28C977cBB58D8C7FF8FCF9F70a2cCA", "uniswap-ur", "HIGH")],
125
+ zapRouters: withBookedZaps("ethereum", [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x4C82D1fBFe28C977cBB58D8C7FF8FCF9F70a2cCA", "uniswap-ur", "HIGH")]),
61
126
  notes: [],
62
127
  },
63
128
  base: {
64
129
  wrappedNative: strict("0x4200000000000000000000000000000000000006"),
65
- zapRouters: [
130
+ zapRouters: withBookedZaps("base", [
66
131
  r("aerodrome-ur", "Aerodrome V1 + Slipstream", "0xC5b6786D7B64767D775877b0B6A319AD946B11B5", "uniswap-ur", "HIGH", false, true),
67
132
  r(UNISWAP_UR, "Uniswap v2/v3/v4", "0xFdf682F51FE81Aa4898F0AE2163d8A55c127fbC7", "uniswap-ur", "HIGH"),
68
133
  r("pancake-ur", "PancakeSwap V3 / Infinity", "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB", "uniswap-ur", "HIGH", true, true),
69
- ],
134
+ ]),
70
135
  notes: [],
71
136
  },
72
137
  bsc: {
73
138
  wrappedNative: strict("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"),
74
- zapRouters: [
139
+ zapRouters: withBookedZaps("bsc", [
75
140
  r("pancake-ur", "PancakeSwap V2 / V3 / Infinity", "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB", "uniswap-ur", "HIGH", false, true),
76
141
  r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH"),
77
- ],
142
+ ]),
78
143
  notes: ["⚠ 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD is Uniswap's UR v1.2, NOT PancakeSwap's: never use it as Pancake's."],
79
144
  },
80
145
  arbitrum: {
81
146
  wrappedNative: strict("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"),
82
- zapRouters: [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH")],
147
+ zapRouters: withBookedZaps("arbitrum", [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH")]),
83
148
  notes: [],
84
149
  },
85
150
  hyperevm: {
86
151
  maxFloorHops: 2,
87
152
  wrappedNative: strict("0x5555555555555555555555555555555555555555"),
88
- zapRouters: [
153
+ zapRouters: withBookedZaps("hyperevm", [
89
154
  r("prjx", "Project X", "0x1EbDFC75FfE3ba3de61E7138a3E8706aC841Af9B", "v3-router", "MEDIUM–HIGH"),
90
155
  r("nest", "nest (CL)", "0xaA26B8e5Cadd04430c32787eCC3AA325e99681e9", "algebra", "HIGH"),
91
156
  r("ramses-ur", "Ramses CL V2", "0xc43b33b5DF826A48DAE764817647824ED4f476a7", "uniswap-ur", "MEDIUM", false, true),
92
157
  r("hyperswap", "HyperSwap V3", "0x6D99e7f6747AF2cDbB5164b6DD50e40D4fDe1e77", "v3-router02", "HIGH", true),
93
- ],
158
+ ]),
94
159
  notes: ["⚠ Small blocks cap a transaction at 3M gas: a buy that graduates a launch may need a big block."],
95
160
  },
96
161
  robinhood: {
97
162
  wrappedNative: strict("0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73"),
98
- zapRouters: [
163
+ zapRouters: withBookedZaps("robinhood", [
99
164
  r(UNISWAP_UR, "Uniswap v2/v3/v4 (+ Fables v4 pools)", "0x8876789976dEcBfCbBbe364623C63652db8C0904", "uniswap-ur", "HIGH"),
100
165
  r("ramses-ur", "Ramses", "0xbFbb2BCBc9dfFA029C27A249ae9BE031E1d83b1C", "uniswap-ur", "HIGH", true, true),
101
- ],
166
+ ]),
102
167
  notes: [],
103
168
  },
104
169
  arc: {
105
170
  wrappedNative: null,
106
- zapRouters: [r(UNISWAP_UR, "Uniswap v4 (native-USDC pools)", "0x4fcA4a51Ab4F23A7447b3284fBd7D73289A89Fb1", "uniswap-ur", "HIGH")],
171
+ zapRouters: withBookedZaps("arc", [r(UNISWAP_UR, "Uniswap v4 (native-USDC pools)", "0x4fcA4a51Ab4F23A7447b3284fBd7D73289A89Fb1", "uniswap-ur", "HIGH")]),
107
172
  notes: [
108
173
  "⚠ The native coin is USDC (18 dp at the EVM level; its ERC-20 view 0x3600000000000000000000000000000000000000 has 6 dp and no deposit()).",
109
174
  "⚠ No WETH9: WRAP_ETH does not apply; only v4 pools in address(0) take the native coin. The zap is for third-token quotes only.",
110
175
  ],
111
176
  },
112
177
  elysium: {
113
- wrappedNative: null,
114
- zapRouters: [],
178
+
179
+ wrappedNative: strict("0xbA876237B0F021A6c6D852d6c26E107997cC5E81"),
180
+
181
+ zapRouters: withBookedZaps("elysium", [r(UNISWAP_UR, "Uniswap v4 (native HYPE / USDC pools)", "0xA13f7611115752DEB2B13813BDDE16A5073e4b45", "uniswap-ur", "HIGH")]),
115
182
  notes: [
116
183
  "⚠ Arbitrum Orbit on HyperEVM: in a contract block.number is HyperEVM's block; the receipt's block is Elysium's.",
117
- "⚠ No zap routers yet (no DEX read back on chain) and no wrapped HYPE address published: the native coin and listed quotes only.",
184
+ "⚠ Depth is Uniswap v4 only (native HYPE / USDC pools, no hooks): route the zap through V4_SWAP (route.v4), never WRAP_ETH; the v3 and V2 pools hold no depth.",
118
185
  ],
119
186
  },
120
187
  };
@@ -123,6 +190,10 @@ export const EVM_CHAINS: Record<ChainKey, EvmChain> = Object.fromEntries(
123
190
  CHAIN_REGISTRY.flatMap((c) => (c.family === "evm" ? [[c.slug, { key: c.slug, chainId: c.chainId, name: c.label, nativeSymbol: c.native.symbol, ...ROUTES[c.slug], ...((c.v2DayOne as boolean) === false ? { v2DayOne: false as const } : {}) }]] : [])),
124
191
  ) as Record<ChainKey, EvmChain>;
125
192
 
193
+ export const FLOOR_ROUTER_ADDRESSES: Readonly<Record<ChainKey, Readonly<Record<string, string>>>> = Object.freeze(
194
+ Object.fromEntries(Object.values(EVM_CHAINS).map((c) => [c.key, Object.freeze(Object.fromEntries(c.zapRouters.map((r) => [r.slot, r.floorRouter])))])),
195
+ ) as Readonly<Record<ChainKey, Readonly<Record<string, string>>>>;
196
+
126
197
  export const v2DayOneChains = (): EvmChain[] => Object.values(EVM_CHAINS).filter((c) => c.v2DayOne !== false);
127
198
  export const chainById = (chainId: number): EvmChain | null => Object.values(EVM_CHAINS).find((c) => c.chainId === chainId) ?? null;
128
199
 
package/src/evm/router.ts CHANGED
@@ -3,7 +3,8 @@
3
3
  import { encodeFunctionData } from "./items.ts";
4
4
  import { deadlineArg } from "./floor/calls.ts";
5
5
  import { EVM_NATIVE, NoRouteError, coinKey } from "../route/graph.ts";
6
- import { chainById } from "./chains.ts";
6
+ import { EVM_CHAINS, chainById } from "./chains.ts";
7
+ import type { ChainKey } from "./chains.ts";
7
8
  import type { Pool } from "../route/graph.ts";
8
9
  import type { HopQuote, RouteQuote } from "../route/quote.ts";
9
10
 
@@ -207,3 +208,27 @@ export function evmRouteCall(q: RouteQuote, p: { router: string; to: string; dea
207
208
  const b: RouterBuy = { path: ids(buys), tokenIn: s.tokenOut, amountIn: 0n, swapData: "0x", minQuoteIn: 0n, minTokensOut: mins(buys), to: p.to, deadline: p.deadline };
208
209
  return call(encodeRouterSwap(s, b, p.chainId), 0n);
209
210
  }
211
+
212
+ export async function floorRouterLive(rpc: { getCode: (address: string) => Promise<string | undefined> }, at: string | { chain: ChainKey; slot: string }): Promise<boolean> {
213
+ const address = floorRouterAt(at);
214
+ const code: unknown = await rpc.getCode(address);
215
+ if (code === undefined) return false;
216
+ if (typeof code !== "string" || !/^0x([0-9a-fA-F]{2})*$/.test(code)) throw new TypeError(`getCode(${address}) returned ${String(code)}, not hex bytes`);
217
+ return code.length > 2;
218
+ }
219
+
220
+ export async function assertFloorRouterLive(rpc: { getCode: (address: string) => Promise<string | undefined> }, at: string | { chain: ChainKey; slot: string }): Promise<string> {
221
+ const address = floorRouterAt(at);
222
+ if (!(await floorRouterLive(rpc, address))) throw new RangeError(`FloorRouter ${address} has no code on this chain yet: it is derived ahead of its deploy; do not send to it (a native coin sent to it is lost)`);
223
+ return address;
224
+ }
225
+
226
+ function floorRouterAt(at: string | { chain: ChainKey; slot: string }): string {
227
+ if (typeof at === "string") {
228
+ if (!/^0x[0-9a-fA-F]{40}$/.test(at)) throw new RangeError(`a FloorRouter is a 20-byte address: ${at}`);
229
+ return at;
230
+ }
231
+ const row = EVM_CHAINS[at.chain]?.zapRouters.find((r) => r.slot === at.slot);
232
+ if (row === undefined) throw new RangeError(`no FloorRouter slot ${at.slot} on ${at.chain}`);
233
+ return row.floorRouter;
234
+ }
package/src/evm/squid.ts CHANGED
@@ -96,19 +96,19 @@ export function buyHookErc20(p: Common & { quote: string; minTokensOut: bigint }
96
96
  };
97
97
  }
98
98
 
99
- export function buyHookNative(p: Common & { zap: string; swapData: string; minQuoteIn: bigint; minTokensOut: bigint }): SquidHook {
99
+ export function buyHookNative(p: Common & { zap: string; swapData: string; minQuoteIn: bigint; minTokensOut: bigint; quote?: string }): SquidHook {
100
100
  checkCommon(p);
101
101
  const user = checkUser(p);
102
102
  if (p.minQuoteIn <= 0n || p.minTokensOut <= 0n) throw new SquidHookError("NO_MINIMUM", "minQuoteIn and minTokensOut must be > 0");
103
103
  const zap = lc(p.zap, "zap");
104
- return {
105
- provider: "FLOOR",
106
- description: "Buy a FLOOR launch token with the native coin",
107
- calls: [
108
- call(SQUID_CALL.FullNativeBalance, zap, 0n, bytesToHex(encodeCall("buyWithEth(uint256,bytes,uint256,uint256,address,uint256)", [p.launchId, p.swapData, p.minQuoteIn, p.minTokensOut, user, p.deadline])), "0x", SQUID_GAS.zapBuy),
109
- call(SQUID_CALL.FullNativeBalance, user, 0n, "0x", "0x", SQUID_GAS.passOn),
110
- ],
111
- };
104
+ const quote = lc(p.quote ?? ZERO, "quote");
105
+ const calls = [
106
+ call(SQUID_CALL.FullNativeBalance, zap, 0n, bytesToHex(encodeCall("buyWithEth(uint256,bytes,uint256,uint256,address,uint256)", [p.launchId, p.swapData, p.minQuoteIn, p.minTokensOut, user, p.deadline])), "0x", SQUID_GAS.zapBuy),
107
+ call(SQUID_CALL.FullNativeBalance, user, 0n, "0x", "0x", SQUID_GAS.passOn),
108
+ ];
109
+
110
+ if (quote !== ZERO) calls.push(call(SQUID_CALL.FullTokenBalance, quote, 0n, bytesToHex(encodeCall("transfer(address,uint256)", [user, SQUID_FULL])), bytesToHex(encodeAbi(["address", "uint256"], [quote, 1n])), SQUID_GAS.transfer));
111
+ return { provider: "FLOOR", description: "Buy a FLOOR launch token with the native coin", calls };
112
112
  }
113
113
 
114
114
  export function sellHook(p: Common & { token: string; tokensIn: bigint; minQuoteOut: bigint; proceedsTo?: string }): SquidHook {