@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/CHANGELOG.md +28 -0
- package/README.md +2 -0
- package/dist/abi/evm.gen.js +5 -0
- package/dist/client/solana/index.js +13 -8
- package/dist/config/generated.js +1 -1
- package/dist/config/registry.gen.js +1 -1
- package/dist/evm/chains.js +79 -18
- package/dist/evm/router.js +25 -1
- package/dist/evm/squid.js +9 -9
- package/dist/evm/zap.js +148 -35
- package/dist/indexer/bodies.js +5 -0
- package/dist/indexer/client.js +2 -0
- package/dist/indexer/contract.js +48 -2
- package/dist/indexer/paths.js +26 -0
- package/dist/indexer/read.js +3 -0
- package/dist/v2/devbuy.js +6 -4
- package/dist/v2/presetRowEvm.js +21 -2
- package/docs/aggregator.md +22 -0
- package/docs/bot.md +8 -0
- package/docs/cursor-pages.md +2 -0
- package/docs/frontend.md +2 -0
- package/docs/wallet.md +2 -0
- package/package.json +1 -1
- package/src/abi/evm.gen.ts +5 -0
- package/src/client/solana/index.ts +13 -8
- package/src/config/generated.ts +1 -1
- package/src/config/registry.gen.ts +1 -1
- package/src/evm/chains.ts +88 -17
- package/src/evm/router.ts +26 -1
- package/src/evm/squid.ts +9 -9
- package/src/evm/zap.ts +185 -36
- package/src/indexer/bodies.ts +7 -0
- package/src/indexer/client.ts +5 -1
- package/src/indexer/contract.ts +48 -2
- package/src/indexer/paths.ts +47 -0
- package/src/indexer/read.ts +5 -2
- package/src/v2/devbuy.ts +6 -4
- package/src/v2/presetRowEvm.ts +21 -2
package/dist/evm/zap.js
CHANGED
|
@@ -3,14 +3,23 @@
|
|
|
3
3
|
import { bytesToHex, checksumAddress, encodeAbi, hexToBytes } from "./abi.js";
|
|
4
4
|
import { encodeFunctionData } from "./items.js";
|
|
5
5
|
|
|
6
|
+
export const AERODROME_SLIPSTREAM_KEY = 0x100000;
|
|
7
|
+
|
|
6
8
|
export const UR_V3_SWAP_EXACT_IN = 0x00;
|
|
7
9
|
export const UR_V2_SWAP_EXACT_IN = 0x08;
|
|
8
10
|
export const UR_WRAP_ETH = 0x0b;
|
|
9
11
|
export const UR_UNWRAP_WETH = 0x0c;
|
|
10
12
|
export const UR_SWEEP = 0x04;
|
|
13
|
+
export const UR_V4_SWAP = 0x10;
|
|
11
14
|
export const UR_MSG_SENDER = "0x0000000000000000000000000000000000000001";
|
|
12
15
|
export const UR_ADDRESS_THIS = "0x0000000000000000000000000000000000000002";
|
|
13
16
|
|
|
17
|
+
export const V4_SWAP_EXACT_IN_SINGLE = 0x06;
|
|
18
|
+
export const V4_SETTLE = 0x0b;
|
|
19
|
+
export const V4_TAKE = 0x0e;
|
|
20
|
+
export const V4_OPEN_DELTA = 0n;
|
|
21
|
+
export const V4_NATIVE = "0x0000000000000000000000000000000000000000";
|
|
22
|
+
|
|
14
23
|
const fn = (name , inputs ) => ({ type: "function", name, inputs, outputs: [], stateMutability: "payable" }) ;
|
|
15
24
|
const tup = (fields ) => fields.map(([name, type]) => ({ name, type }));
|
|
16
25
|
|
|
@@ -33,34 +42,131 @@ export function algebraPath(tokens ) {
|
|
|
33
42
|
return "0x" + tokens.map((t) => bytesToHex(hexToBytes(t)).slice(2)).join("");
|
|
34
43
|
}
|
|
35
44
|
|
|
45
|
+
const UR_FORKS = ["uniswap", "aerodrome", "pancake", "ramses"];
|
|
46
|
+
|
|
47
|
+
const isNative = (a ) => BigInt(checksumAddress(a)) === 0n;
|
|
48
|
+
|
|
36
49
|
const checkRoute = (p ) => {
|
|
37
50
|
if (p.amountIn <= 0n) throw new RangeError("amountIn must be > 0");
|
|
38
51
|
if (p.minQuoteOut <= 0n) throw new RangeError("minQuoteOut must be > 0 (the NO_MINIMUM rule)");
|
|
39
|
-
|
|
52
|
+
const { tokens } = p.route;
|
|
53
|
+
if (tokens.length < 2) throw new RangeError("a route is at least two tokens");
|
|
54
|
+
if (p.input !== undefined && p.input !== "native" && p.input !== "token") throw new RangeError(`input ${String(p.input)} is "native" or "token"`);
|
|
55
|
+
if (p.output !== undefined && p.output !== "native" && p.output !== "token") throw new RangeError(`output ${String(p.output)} is "native" or "token"`);
|
|
56
|
+
if (p.urFork !== undefined && (p.family !== "uniswap-ur" || !UR_FORKS.includes(p.urFork))) {
|
|
57
|
+
throw new RangeError(`urFork ${String(p.urFork)} names a uniswap-ur row's router: ${UR_FORKS.join(", ")}`);
|
|
58
|
+
}
|
|
59
|
+
const [first, last] = [tokens[0], tokens[tokens.length - 1]];
|
|
60
|
+
if (BigInt(checksumAddress(first)) === BigInt(checksumAddress(last))) throw new RangeError("a route swaps a coin into itself");
|
|
61
|
+
if (p.route.v4) {
|
|
62
|
+
if (p.family !== "uniswap-ur") throw new RangeError("a v4 route goes through the Universal Router (uniswap-ur)");
|
|
63
|
+
if ((p.urFork ?? "uniswap") !== "uniswap") throw new RangeError("a v4 route goes through Uniswap's own Universal Router");
|
|
64
|
+
const ends = { nativeIn: isNative(first), nativeOut: isNative(last) };
|
|
65
|
+
if (p.input !== undefined && (p.input === "native") !== ends.nativeIn) throw new RangeError(`input "${p.input}" is not the v4 route's first currency`);
|
|
66
|
+
if (p.output !== undefined && (p.output === "native") !== ends.nativeOut) throw new RangeError(`output "${p.output}" is not the v4 route's last currency`);
|
|
67
|
+
return ends;
|
|
68
|
+
}
|
|
69
|
+
if (tokens.some(isNative)) throw new RangeError("a V2 / V3 route names the wrapped native, never address(0) (only a v4 route holds the native coin)");
|
|
70
|
+
const ends = { nativeIn: (p.input ?? "native") === "native", nativeOut: (p.output ?? "token") === "native" };
|
|
71
|
+
if (ends.nativeIn && ends.nativeOut) throw new RangeError("a route swaps the native coin into itself");
|
|
72
|
+
return ends;
|
|
40
73
|
};
|
|
41
74
|
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
75
|
+
export function v4PoolKey(tokenIn , tokenOut , pool ) {
|
|
76
|
+
const a = checksumAddress(tokenIn);
|
|
77
|
+
const b = checksumAddress(tokenOut);
|
|
78
|
+
if (BigInt(a) === BigInt(b)) throw new RangeError("a v4 swap is between two different currencies");
|
|
79
|
+
if (!Number.isInteger(pool.fee) || pool.fee < 0 || pool.fee >= 1 << 24) throw new RangeError(`fee ${pool.fee} is not a uint24`);
|
|
80
|
+
if (!Number.isInteger(pool.tickSpacing) || pool.tickSpacing < 1 || pool.tickSpacing > 32767) throw new RangeError(`tick spacing ${pool.tickSpacing} is not 1 ..= 32767`);
|
|
81
|
+
const zeroForOne = BigInt(a) < BigInt(b);
|
|
82
|
+
const hooks = checksumAddress(pool.hooks ?? V4_NATIVE);
|
|
83
|
+
return { key: { currency0: zeroForOne ? a : b, currency1: zeroForOne ? b : a, fee: pool.fee, tickSpacing: pool.tickSpacing, hooks }, zeroForOne };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const UINT128 = 1n << 128n;
|
|
87
|
+
const UR_EXECUTE = [fn("execute", [{ name: "commands", type: "bytes" }, { name: "inputs", type: "bytes[]" }, { name: "deadline", type: "uint256" }])];
|
|
88
|
+
const cmds = (cs ) => "0x" + cs.map((c) => c.toString(16).padStart(2, "0")).join("");
|
|
89
|
+
|
|
90
|
+
function universalRouterV4(p , pool ) {
|
|
91
|
+
const { tokens } = p.route;
|
|
92
|
+
if (tokens.length !== 2) throw new RangeError("a v4 route is one pool: [currency in, currency out]");
|
|
93
|
+
if (p.route.fees || p.route.stable || p.route.factory) throw new RangeError("a v4 route names its pool in `v4` only");
|
|
94
|
+
if (p.amountIn >= UINT128 || p.minQuoteOut >= UINT128) throw new RangeError("a v4 amount is a uint128");
|
|
95
|
+
const [tokenIn, tokenOut] = tokens;
|
|
96
|
+
const { key, zeroForOne } = v4PoolKey(tokenIn, tokenOut, pool);
|
|
97
|
+
const nativeOut = isNative(tokenOut);
|
|
98
|
+
const swap = encodeAbi(
|
|
99
|
+
["((address,address,uint24,int24,address),bool,uint128,uint128,uint256,bytes)"],
|
|
100
|
+
[[[key.currency0, key.currency1, BigInt(key.fee), BigInt(key.tickSpacing), key.hooks], zeroForOne, p.amountIn, p.minQuoteOut, 0n, pool.hookData ?? "0x"]],
|
|
101
|
+
);
|
|
102
|
+
const settle = encodeAbi(["address", "uint256", "bool"], [checksumAddress(tokenIn), V4_OPEN_DELTA, false]);
|
|
103
|
+
const take = encodeAbi(["address", "address", "uint256"], [checksumAddress(tokenOut), nativeOut ? UR_ADDRESS_THIS : UR_MSG_SENDER, V4_OPEN_DELTA]);
|
|
104
|
+
const v4 = bytesToHex(encodeAbi(["bytes", "bytes[]"], [cmds([V4_SWAP_EXACT_IN_SINGLE, V4_SETTLE, V4_TAKE]), [swap, settle, take]]));
|
|
105
|
+
|
|
106
|
+
const nativeIn = isNative(tokenIn);
|
|
107
|
+
const sweep = (min ) => bytesToHex(encodeAbi(["address", "address", "uint256"], [V4_NATIVE, UR_MSG_SENDER, min]));
|
|
108
|
+
const inputs = nativeOut ? [v4, sweep(p.minQuoteOut)] : nativeIn ? [v4, sweep(0n)] : [v4];
|
|
109
|
+
return encodeFunctionData(UR_EXECUTE, "execute", { commands: cmds(nativeOut ? [UR_V4_SWAP, UR_SWEEP] : nativeIn ? [UR_V4_SWAP, UR_SWEEP] : [UR_V4_SWAP]), inputs, deadline: p.deadline });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const UR_SWAP_HEAD = ["address", "uint256", "uint256", "bytes", "bool"];
|
|
113
|
+
|
|
114
|
+
function aerodromeKey(k ) {
|
|
115
|
+
if (!Number.isInteger(k) || k < 1 || k >= 1 << 24) throw new RangeError(`Aerodrome key ${k} is not a tick spacing`);
|
|
116
|
+
if (k < AERODROME_SLIPSTREAM_KEY) return AERODROME_SLIPSTREAM_KEY | k;
|
|
117
|
+
if (k >>> 20 !== 1) throw new RangeError(`Aerodrome key ${k} names another factory than Slipstream's (0x100000 | tickSpacing)`);
|
|
118
|
+
return k;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function universalRouter(p , e ) {
|
|
122
|
+
const fork = p.urFork ?? "uniswap";
|
|
123
|
+
const to = e.nativeOut ? UR_ADDRESS_THIS : UR_MSG_SENDER;
|
|
124
|
+
const commands = [];
|
|
125
|
+
const inputs = [];
|
|
126
|
+
if (e.nativeIn) {
|
|
127
|
+
commands.push(UR_WRAP_ETH);
|
|
128
|
+
inputs.push(bytesToHex(encodeAbi(["address", "uint256"], [UR_ADDRESS_THIS, p.amountIn])));
|
|
129
|
+
}
|
|
46
130
|
if (p.route.fees) {
|
|
47
|
-
|
|
48
|
-
|
|
131
|
+
const keys = fork === "aerodrome" ? p.route.fees.map(aerodromeKey) : p.route.fees;
|
|
132
|
+
const head = [to, p.amountIn, p.minQuoteOut, v3Path(p.route.tokens, keys), false];
|
|
133
|
+
const swap = fork === "uniswap" ? encodeAbi([...UR_SWAP_HEAD, "uint256[]"], [...head, []])
|
|
134
|
+
: fork === "aerodrome" ? encodeAbi([...UR_SWAP_HEAD, "bool"], [...head, false])
|
|
135
|
+
: encodeAbi(UR_SWAP_HEAD, head);
|
|
136
|
+
commands.push(UR_V3_SWAP_EXACT_IN);
|
|
137
|
+
inputs.push(bytesToHex(swap));
|
|
49
138
|
} else {
|
|
50
|
-
|
|
51
|
-
|
|
139
|
+
if (fork !== "uniswap") throw new RangeError(`a V2 leg through ${fork}'s Universal Router is not spelled (its V2_SWAP_EXACT_IN input is its own)`);
|
|
140
|
+
commands.push(UR_V2_SWAP_EXACT_IN);
|
|
141
|
+
inputs.push(bytesToHex(encodeAbi(["address", "uint256", "uint256", "address[]", "bool", "uint256[]"], [to, p.amountIn, p.minQuoteOut, [...p.route.tokens], false, []])));
|
|
52
142
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
143
|
+
if (e.nativeOut) {
|
|
144
|
+
commands.push(UR_UNWRAP_WETH);
|
|
145
|
+
inputs.push(bytesToHex(encodeAbi(["address", "uint256"], [UR_MSG_SENDER, p.minQuoteOut])));
|
|
146
|
+
}
|
|
147
|
+
if (e.nativeIn) {
|
|
148
|
+
|
|
149
|
+
commands.push(UR_SWEEP);
|
|
150
|
+
inputs.push(bytesToHex(encodeAbi(["address", "address", "uint256"], [V4_NATIVE, UR_MSG_SENDER, 0n])));
|
|
151
|
+
}
|
|
152
|
+
return encodeFunctionData(UR_EXECUTE, "execute", { commands: cmds(commands), inputs, deadline: p.deadline });
|
|
56
153
|
}
|
|
57
154
|
|
|
155
|
+
const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
|
|
58
156
|
const REFUND_ETH = [fn("refundETH", [])];
|
|
59
157
|
const REFUND_NATIVE = [fn("refundNativeToken", [])];
|
|
158
|
+
const UNWRAP = (name ) => [fn(name, [{ name: "amountMinimum", type: "uint256" }, { name: "recipient", type: "address" }])];
|
|
60
159
|
|
|
61
|
-
|
|
160
|
+
const peripheryTail = (p , e , refund , unwrap ) =>
|
|
161
|
+
e.nativeIn ? [encodeFunctionData(refund === "refundETH" ? REFUND_ETH : REFUND_NATIVE, refund)]
|
|
162
|
+
: e.nativeOut ? [encodeFunctionData(UNWRAP(unwrap), unwrap, { amountMinimum: p.minQuoteOut, recipient: p.zap })]
|
|
163
|
+
: [];
|
|
164
|
+
|
|
165
|
+
function v3Router(p , v02 , e ) {
|
|
62
166
|
const fees = p.route.fees;
|
|
63
167
|
if (!fees) throw new RangeError("a V3 router route needs its fees");
|
|
168
|
+
if (e.nativeOut && !v02 && !p.router) throw new RangeError("a SwapRouter v1 native out is paid to the router, then unwrapped: pass the zap's `router`");
|
|
169
|
+
const recipient = !e.nativeOut ? p.zap : v02 ? UR_ADDRESS_THIS : checksumAddress(p.router );
|
|
64
170
|
const [tokenIn, tokenOut] = [p.route.tokens[0], p.route.tokens[p.route.tokens.length - 1]];
|
|
65
171
|
let swap ;
|
|
66
172
|
if (p.route.tokens.length === 2) {
|
|
@@ -68,61 +174,68 @@ function v3Router(p , v02 ) {
|
|
|
68
174
|
? [["tokenIn", "address"], ["tokenOut", "address"], ["fee", "uint24"], ["recipient", "address"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"], ["sqrtPriceLimitX96", "uint160"]]
|
|
69
175
|
: [["tokenIn", "address"], ["tokenOut", "address"], ["fee", "uint24"], ["recipient", "address"], ["deadline", "uint256"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"], ["sqrtPriceLimitX96", "uint160"]];
|
|
70
176
|
const abi = [fn("exactInputSingle", [{ name: "params", type: "tuple", components: tup(fields) }])];
|
|
71
|
-
swap = encodeFunctionData(abi, "exactInputSingle", { params: { tokenIn, tokenOut, fee: BigInt(fees[0]), recipient
|
|
177
|
+
swap = encodeFunctionData(abi, "exactInputSingle", { params: { tokenIn, tokenOut, fee: BigInt(fees[0]), recipient, deadline: p.deadline, amountIn: p.amountIn, amountOutMinimum: p.minQuoteOut, sqrtPriceLimitX96: 0n } });
|
|
72
178
|
} else {
|
|
73
179
|
const fields = v02
|
|
74
180
|
? [["path", "bytes"], ["recipient", "address"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"]]
|
|
75
181
|
: [["path", "bytes"], ["recipient", "address"], ["deadline", "uint256"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"]];
|
|
76
182
|
const abi = [fn("exactInput", [{ name: "params", type: "tuple", components: tup(fields) }])];
|
|
77
|
-
swap = encodeFunctionData(abi, "exactInput", { params: { path: v3Path(p.route.tokens, fees), recipient
|
|
183
|
+
swap = encodeFunctionData(abi, "exactInput", { params: { path: v3Path(p.route.tokens, fees), recipient, deadline: p.deadline, amountIn: p.amountIn, amountOutMinimum: p.minQuoteOut } });
|
|
78
184
|
}
|
|
79
|
-
const
|
|
80
|
-
if (v02) return encodeFunctionData([fn("multicall", [{ name: "deadline", type: "uint256" }, { name: "data", type: "bytes[]" }])], "multicall", { deadline: p.deadline, data
|
|
81
|
-
return encodeFunctionData([fn("multicall", [{ name: "data", type: "bytes[]" }])], "multicall", { data
|
|
185
|
+
const data = [swap, ...peripheryTail(p, e, "refundETH", "unwrapWETH9")];
|
|
186
|
+
if (v02) return encodeFunctionData([fn("multicall", [{ name: "deadline", type: "uint256" }, { name: "data", type: "bytes[]" }])], "multicall", { deadline: p.deadline, data });
|
|
187
|
+
return encodeFunctionData([fn("multicall", [{ name: "data", type: "bytes[]" }])], "multicall", { data });
|
|
82
188
|
}
|
|
83
189
|
|
|
84
|
-
function algebra(p ) {
|
|
190
|
+
function algebra(p , e ) {
|
|
191
|
+
const recipient = e.nativeOut ? ADDRESS_ZERO : p.zap;
|
|
85
192
|
const [tokenIn, tokenOut] = [p.route.tokens[0], p.route.tokens[p.route.tokens.length - 1]];
|
|
86
193
|
let swap ;
|
|
87
194
|
if (p.route.tokens.length === 2) {
|
|
88
195
|
const fields = [["tokenIn", "address"], ["tokenOut", "address"], ["recipient", "address"], ["deadline", "uint256"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"], ["limitSqrtPrice", "uint160"]];
|
|
89
|
-
swap = encodeFunctionData([fn("exactInputSingle", [{ name: "params", type: "tuple", components: tup(fields) }])], "exactInputSingle", { params: { tokenIn, tokenOut, recipient
|
|
196
|
+
swap = encodeFunctionData([fn("exactInputSingle", [{ name: "params", type: "tuple", components: tup(fields) }])], "exactInputSingle", { params: { tokenIn, tokenOut, recipient, deadline: p.deadline, amountIn: p.amountIn, amountOutMinimum: p.minQuoteOut, limitSqrtPrice: 0n } });
|
|
90
197
|
} else {
|
|
91
198
|
const fields = [["path", "bytes"], ["recipient", "address"], ["deadline", "uint256"], ["amountIn", "uint256"], ["amountOutMinimum", "uint256"]];
|
|
92
|
-
swap = encodeFunctionData([fn("exactInput", [{ name: "params", type: "tuple", components: tup(fields) }])], "exactInput", { params: { path: algebraPath(p.route.tokens), recipient
|
|
199
|
+
swap = encodeFunctionData([fn("exactInput", [{ name: "params", type: "tuple", components: tup(fields) }])], "exactInput", { params: { path: algebraPath(p.route.tokens), recipient, deadline: p.deadline, amountIn: p.amountIn, amountOutMinimum: p.minQuoteOut } });
|
|
93
200
|
}
|
|
94
|
-
return encodeFunctionData([fn("multicall", [{ name: "data", type: "bytes[]" }])], "multicall", { data: [swap,
|
|
201
|
+
return encodeFunctionData([fn("multicall", [{ name: "data", type: "bytes[]" }])], "multicall", { data: [swap, ...peripheryTail(p, e, "refundNativeToken", "unwrapWNativeToken")] });
|
|
95
202
|
}
|
|
96
203
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
204
|
+
const v2Name = (e ) => (e.nativeIn ? "swapExactETHForTokens" : e.nativeOut ? "swapExactTokensForETH" : "swapExactTokensForTokens");
|
|
205
|
+
|
|
206
|
+
function v2Router(p , e ) {
|
|
207
|
+
const name = v2Name(e);
|
|
208
|
+
const head = e.nativeIn ? [] : [["amountIn", "uint256"]];
|
|
209
|
+
const abi = [fn(name, tup([...head, ["amountOutMin", "uint256"], ["path", "address[]"], ["to", "address"], ["deadline", "uint256"]]))];
|
|
210
|
+
return encodeFunctionData(abi, name, { amountIn: p.amountIn, amountOutMin: p.minQuoteOut, path: [...p.route.tokens], to: p.zap, deadline: p.deadline });
|
|
100
211
|
}
|
|
101
212
|
|
|
102
|
-
function aerodromeV2(p ) {
|
|
213
|
+
function aerodromeV2(p , e ) {
|
|
103
214
|
const { tokens, stable, factory } = p.route;
|
|
104
215
|
if (!stable || stable.length !== tokens.length - 1 || !factory) throw new RangeError("an Aerodrome route needs a stable flag per hop and the factory");
|
|
105
216
|
const route = { name: "routes", type: "tuple[]", components: tup([["from", "address"], ["to", "address"], ["stable", "bool"], ["factory", "address"]]) };
|
|
106
|
-
const
|
|
217
|
+
const name = v2Name(e);
|
|
218
|
+
const head = e.nativeIn ? [] : [{ name: "amountIn", type: "uint256" }];
|
|
219
|
+
const abi = [fn(name, [...head, { name: "amountOutMin", type: "uint256" }, route, { name: "to", type: "address" }, { name: "deadline", type: "uint256" }])];
|
|
107
220
|
const routes = stable.map((s, i) => ({ from: tokens[i], to: tokens[i + 1], stable: s, factory }));
|
|
108
|
-
return encodeFunctionData(abi,
|
|
221
|
+
return encodeFunctionData(abi, name, { amountIn: p.amountIn, amountOutMin: p.minQuoteOut, routes, to: p.zap, deadline: p.deadline });
|
|
109
222
|
}
|
|
110
223
|
|
|
111
224
|
export function zapSwapData(p ) {
|
|
112
|
-
checkRoute(p);
|
|
225
|
+
const e = checkRoute(p);
|
|
113
226
|
checksumAddress(p.zap);
|
|
114
227
|
switch (p.family) {
|
|
115
228
|
case "uniswap-ur":
|
|
116
|
-
return universalRouter(p);
|
|
229
|
+
return p.route.v4 ? universalRouterV4(p, p.route.v4) : universalRouter(p, e);
|
|
117
230
|
case "v3-router":
|
|
118
|
-
return v3Router(p, false);
|
|
231
|
+
return v3Router(p, false, e);
|
|
119
232
|
case "v3-router02":
|
|
120
|
-
return v3Router(p, true);
|
|
233
|
+
return v3Router(p, true, e);
|
|
121
234
|
case "algebra":
|
|
122
|
-
return algebra(p);
|
|
235
|
+
return algebra(p, e);
|
|
123
236
|
case "v2-router":
|
|
124
|
-
return v2Router(p);
|
|
237
|
+
return v2Router(p, e);
|
|
125
238
|
case "aerodrome-v2":
|
|
126
|
-
return aerodromeV2(p);
|
|
239
|
+
return aerodromeV2(p, e);
|
|
127
240
|
}
|
|
128
241
|
}
|
package/dist/indexer/bodies.js
CHANGED
|
@@ -251,6 +251,9 @@ export const LAUNCHES = object({
|
|
|
251
251
|
cursors: perRow(str), keys: perRow(nullable(str)), next: optional(nullable(str)),
|
|
252
252
|
});
|
|
253
253
|
|
|
254
|
+
export const LAUNCH_LIST = object({ quote: str, total: int, launches: array(LISTED_LAUNCH), cursors: array(str), keys: array(nullable(str)), next: nullable(str) });
|
|
255
|
+
export const LAUNCH_LISTS = object({ indexed, lists: array(LAUNCH_LIST) });
|
|
256
|
+
|
|
254
257
|
const SEARCH_SERVED_TIER = (v, p) => {
|
|
255
258
|
const n = int(v, p);
|
|
256
259
|
if (n < 0 || n > 4) throw new ShapeError(p, "a tier 0..4", v);
|
|
@@ -330,6 +333,8 @@ export const CANDLES = object({
|
|
|
330
333
|
candles: array(CANDLE),
|
|
331
334
|
});
|
|
332
335
|
|
|
336
|
+
export const CANDLES_MANY = object({ indexed, interval: str, series: array(CANDLES), missing: array(str) });
|
|
337
|
+
|
|
333
338
|
export const CANDLE_BUNDLE = object({
|
|
334
339
|
indexed,
|
|
335
340
|
launch: str,
|
package/dist/indexer/client.js
CHANGED
|
@@ -21,6 +21,7 @@ export const routePath = {
|
|
|
21
21
|
floorRouted: (a) => indexerPath.floorRouted(a ?? {}),
|
|
22
22
|
events: (a) => indexerPath.events(a.fromBlock, a.toBlock),
|
|
23
23
|
launches: (a) => indexerPath.launches(a ?? {}),
|
|
24
|
+
launchLists: (a) => indexerPath.launchLists(a),
|
|
24
25
|
search: (a) => indexerPath.search(a),
|
|
25
26
|
launch: (a) => indexerPath.launch(a.launch),
|
|
26
27
|
launchState: (a) => indexerPath.launchState(a.launch),
|
|
@@ -40,6 +41,7 @@ export const routePath = {
|
|
|
40
41
|
price: (a) => indexerPath.price(a.launch),
|
|
41
42
|
highs: ({ launch, ...q }) => indexerPath.highs(launch, q),
|
|
42
43
|
candles: (a) => indexerPath.candles(a),
|
|
44
|
+
candlesMany: (a) => indexerPath.candlesMany(a),
|
|
43
45
|
candleBundle: ({ launch, ...q }) => indexerPath.candleBundle(launch, q),
|
|
44
46
|
walletTrades: ({ wallet, ...q }) => indexerPath.walletTrades(wallet, q),
|
|
45
47
|
tonActivity: ({ wallet, ...q }) => indexerPath.tonActivity(wallet, q),
|
package/dist/indexer/contract.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { unknown } from "./decode.js";
|
|
4
4
|
import * as B from "./bodies.js";
|
|
5
5
|
import * as P from "./partners.js";
|
|
6
|
-
import { FIRSTS_MAX, IDS_MAX, INBOX_PAGE_DEFAULT, INBOX_PAGE_MAX, LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX, LAUNCH_CURSOR_MAX, LAUNCH_SORTS, PRESET_FILTER_MAX, STREAM_STATE_MAX, WALLET_CURSOR_MAX, WALLET_PAGE_DEFAULT, WALLET_PAGE_MAX } from "./paths.js";
|
|
6
|
+
import { CANDLES_MANY_IDS_MAX, CANDLES_MANY_LIMIT_DEFAULT, CANDLES_MANY_ROWS_MAX, FIRSTS_MAX, IDS_MAX, LAUNCH_LISTS_QUOTES_MAX, LAUNCH_LISTS_ROWS_MAX, INBOX_PAGE_DEFAULT, INBOX_PAGE_MAX, LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX, LAUNCH_CURSOR_MAX, LAUNCH_SORTS, PRESET_FILTER_MAX, STREAM_STATE_MAX, WALLET_CURSOR_MAX, WALLET_PAGE_DEFAULT, WALLET_PAGE_MAX } from "./paths.js";
|
|
7
7
|
import { SEARCH_PAGE_DEFAULT, SEARCH_PAGE_MAX, SEARCH_Q_MAX } from "./search.js";
|
|
8
8
|
|
|
9
9
|
export const UNITS = {
|
|
@@ -148,6 +148,25 @@ export const INDEXER_CONTRACT = {
|
|
|
148
148
|
errors: [...GATED, "bad_query"],
|
|
149
149
|
body: B.LAUNCHES,
|
|
150
150
|
}),
|
|
151
|
+
|
|
152
|
+
launchLists: site({
|
|
153
|
+
pattern: "/floor-amm/launch-lists",
|
|
154
|
+
v2: true,
|
|
155
|
+
query: {
|
|
156
|
+
quotes: { kind: "list", doc: "one list per quote coin, in this order (no repeat)", required: true, min: 1, max: LAUNCH_LISTS_QUOTES_MAX },
|
|
157
|
+
cursors: { kind: "list", doc: "parallel to quotes, one each: that list's page next (- = its first page)", max: LAUNCH_LISTS_QUOTES_MAX },
|
|
158
|
+
sort: { kind: "enum", doc: "the order (larger first with order=desc)", values: LAUNCH_SORTS, default: "created" },
|
|
159
|
+
order: { kind: "enum", doc: "asc or desc", values: ["asc", "desc"], default: "desc" },
|
|
160
|
+
creator: { kind: "string", doc: "launches by this creator" },
|
|
161
|
+
rankable: { kind: "bool", doc: "true (or 1) listed only, false (or 0) unlisted only" },
|
|
162
|
+
graduated: { kind: "bool", doc: "graduated or not (true / false, or 1 / 0)" },
|
|
163
|
+
preset: PRESETS,
|
|
164
|
+
limit: LIMIT(LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX),
|
|
165
|
+
},
|
|
166
|
+
page: limit(LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX),
|
|
167
|
+
errors: [...GATED, "bad_query"],
|
|
168
|
+
body: B.LAUNCH_LISTS,
|
|
169
|
+
}),
|
|
151
170
|
search: site({
|
|
152
171
|
pattern: "/floor-amm/search",
|
|
153
172
|
v2: true,
|
|
@@ -219,6 +238,20 @@ export const INDEXER_CONTRACT = {
|
|
|
219
238
|
errors: [...GATED, "bad_query", "unknown_launch", "not_found"],
|
|
220
239
|
body: B.CANDLES,
|
|
221
240
|
}),
|
|
241
|
+
|
|
242
|
+
candlesMany: site({
|
|
243
|
+
pattern: "/floor-amm/candles/many",
|
|
244
|
+
aliases: ["/floor-amm/v2/candles/many"],
|
|
245
|
+
query: {
|
|
246
|
+
ids: { kind: "list", doc: "these launches (ids or tokens), one series each in the order asked", required: true, min: 1, max: CANDLES_MANY_IDS_MAX },
|
|
247
|
+
interval: { kind: "enum", doc: "the bucket", values: B.CANDLE_INTERVALS, default: "1h" },
|
|
248
|
+
before: { kind: "unix", doc: "the newest limit traded buckets starting before it (absent: past the indexed head)" },
|
|
249
|
+
limit: { kind: "int", doc: "buckets per launch", min: 1, max: B.CANDLES_MAX, default: CANDLES_MANY_LIMIT_DEFAULT },
|
|
250
|
+
},
|
|
251
|
+
page: limit(CANDLES_MANY_LIMIT_DEFAULT, B.CANDLES_MAX),
|
|
252
|
+
errors: [...GATED, "bad_query"],
|
|
253
|
+
body: B.CANDLES_MANY,
|
|
254
|
+
}),
|
|
222
255
|
candleBundle: site({
|
|
223
256
|
pattern: "/floor-amm/launches/<launch>/candle-bundle",
|
|
224
257
|
v2: true,
|
|
@@ -429,6 +462,14 @@ export function queryRefusal(name , q )
|
|
|
429
462
|
}
|
|
430
463
|
}
|
|
431
464
|
|
|
465
|
+
const prod = ROWS_PRODUCT[name];
|
|
466
|
+
if (prod !== undefined) {
|
|
467
|
+
const n = (q.get(prod.list) ?? "").split(",").filter((s) => s !== "").length;
|
|
468
|
+
const raw = q.get("limit");
|
|
469
|
+
const lim = raw === null || raw === "" ? routeLimit(name) .default : Number(raw);
|
|
470
|
+
if (n * lim > prod.max) return `${prod.list} × limit must be at most ${prod.max} (asked ${n} × ${lim})`;
|
|
471
|
+
}
|
|
472
|
+
|
|
432
473
|
const pg = INDEXER_CONTRACT[name].page;
|
|
433
474
|
if (pg.kind === "cursor" && pg.optIn !== undefined && q.get(pg.cursor) !== null) {
|
|
434
475
|
const raw = q.get("limit");
|
|
@@ -437,7 +478,12 @@ export function queryRefusal(name , q )
|
|
|
437
478
|
return spanRefusal(name, q);
|
|
438
479
|
}
|
|
439
480
|
|
|
440
|
-
const
|
|
481
|
+
const ROWS_PRODUCT = {
|
|
482
|
+
launchLists: { list: "quotes", max: LAUNCH_LISTS_ROWS_MAX },
|
|
483
|
+
candlesMany: { list: "ids", max: CANDLES_MANY_ROWS_MAX },
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
const TABLE_REQUIRED = new Set (["search", "launchLists", "candlesMany"]);
|
|
441
487
|
|
|
442
488
|
const BOOLS = { true: true, false: false, 1: true, 0: false };
|
|
443
489
|
|
package/dist/indexer/paths.js
CHANGED
|
@@ -9,6 +9,7 @@ export const INDEXER_ROUTES = {
|
|
|
9
9
|
floorRouted: { pattern: "/floor-amm/floor-routed", keys: ["limit", "cursor"] },
|
|
10
10
|
events: { pattern: "/floor-amm/events", keys: ["fromBlock", "toBlock"] },
|
|
11
11
|
launches: { pattern: "/floor-amm/launches", keys: ["sort", "order", "q", "ids", "quote", "creator", "rankable", "graduated", "preset", "limit", "cursor", "offset"] },
|
|
12
|
+
launchLists: { pattern: "/floor-amm/launch-lists", keys: ["quotes", "cursors", "sort", "order", "creator", "rankable", "graduated", "preset", "limit"] },
|
|
12
13
|
search: { pattern: "/floor-amm/search", keys: ["q", "limit", "cursor", "rankable", "graduated", "quote", "preset"] },
|
|
13
14
|
launch: { pattern: "/floor-amm/launches/<launch>", keys: [] },
|
|
14
15
|
launchState: { pattern: "/floor-amm/launches/<launch>/state", keys: [] },
|
|
@@ -29,6 +30,7 @@ export const INDEXER_ROUTES = {
|
|
|
29
30
|
highs: { pattern: "/floor-amm/launches/<launch>/highs", keys: ["atLeast", "limit"] },
|
|
30
31
|
candleBundle: { pattern: "/floor-amm/launches/<launch>/candle-bundle", keys: ["intervals", "limit"] },
|
|
31
32
|
candles: { pattern: "/floor-amm/candles", keys: ["launch", "interval", "from", "to", "before", "limit"] },
|
|
33
|
+
candlesMany: { pattern: "/floor-amm/candles/many", keys: ["ids", "interval", "before", "limit"] },
|
|
32
34
|
walletTrades: { pattern: "/floor-amm/wallets/<wallet>/trades", keys: ["limit", "before", "launch"] },
|
|
33
35
|
tonActivity: { pattern: "/floor-amm/wallets/<wallet>/ton-activity", keys: ["limit", "before"] },
|
|
34
36
|
tonOutcome: { pattern: "/floor-amm/wallets/<wallet>/ton-outcome", keys: ["queryId"] },
|
|
@@ -54,6 +56,15 @@ export const LAUNCHES_PAGE_MAX = 1_000;
|
|
|
54
56
|
|
|
55
57
|
export const LAUNCHES_PAGE_DEFAULT = 100;
|
|
56
58
|
|
|
59
|
+
export const LAUNCH_LISTS_QUOTES_MAX = 16;
|
|
60
|
+
export const LAUNCH_LISTS_ROWS_MAX = 1_000;
|
|
61
|
+
|
|
62
|
+
export const LAUNCH_LISTS_FIRST = "-";
|
|
63
|
+
|
|
64
|
+
export const CANDLES_MANY_IDS_MAX = 40;
|
|
65
|
+
export const CANDLES_MANY_LIMIT_DEFAULT = 1_000;
|
|
66
|
+
export const CANDLES_MANY_ROWS_MAX = 40_000;
|
|
67
|
+
|
|
57
68
|
export const LAUNCH_CURSOR_MAX = 512;
|
|
58
69
|
|
|
59
70
|
export const WALLET_PAGE_DEFAULT = 100;
|
|
@@ -90,6 +101,10 @@ const presets = (p )
|
|
|
90
101
|
const launchPath = (id , tail = "") => `/floor-amm/launches/${seg(id)}${tail}`;
|
|
91
102
|
const walletPath = (w , tail ) => `/floor-amm/wallets/${seg(w)}${tail}`;
|
|
92
103
|
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
93
108
|
export const indexerPath = {
|
|
94
109
|
head: () => "/floor-amm/head",
|
|
95
110
|
latestBlock: () => "/floor-amm/latest-block",
|
|
@@ -113,6 +128,13 @@ export const indexerPath = {
|
|
|
113
128
|
if (q.preset !== undefined && q.preset.length > PRESET_FILTER_MAX) throw new RangeError(`at most ${PRESET_FILTER_MAX} presets`);
|
|
114
129
|
return `/floor-amm/search${query({ q: q.q, limit: q.limit, cursor: q.cursor, rankable: q.rankable, graduated: q.graduated, quote: q.quote, preset: presets(q.preset) })}`;
|
|
115
130
|
},
|
|
131
|
+
launchLists: (q ) => {
|
|
132
|
+
if (q.quotes.length < 1 || q.quotes.length > LAUNCH_LISTS_QUOTES_MAX) throw new RangeError(`1..${LAUNCH_LISTS_QUOTES_MAX} quotes`);
|
|
133
|
+
if (q.cursors !== undefined && q.cursors.length !== q.quotes.length) throw new RangeError("one cursor per quote");
|
|
134
|
+
if (q.preset !== undefined && q.preset.length > PRESET_FILTER_MAX) throw new RangeError(`at most ${PRESET_FILTER_MAX} presets`);
|
|
135
|
+
const cursors = q.cursors?.some((c) => c !== null && c !== "") ? q.cursors.map((c) => (c === null || c === "" ? LAUNCH_LISTS_FIRST : c)) : undefined;
|
|
136
|
+
return `/floor-amm/launch-lists${query({ quotes: q.quotes, cursors, sort: q.sort, order: q.order, creator: q.creator, rankable: q.rankable, graduated: q.graduated, preset: presets(q.preset), limit: q.limit })}`;
|
|
137
|
+
},
|
|
116
138
|
launch: (id ) => launchPath(id),
|
|
117
139
|
launchState: (id ) => launchPath(id, "/state"),
|
|
118
140
|
milestones: (id ) => launchPath(id, "/milestones"),
|
|
@@ -138,6 +160,10 @@ export const indexerPath = {
|
|
|
138
160
|
if (q.limit !== undefined && q.before === undefined) throw new RangeError("limit is read only with before");
|
|
139
161
|
return `/floor-amm/candles${query({ launch: need(q.launch), interval: q.interval, from: q.from, to: q.to, before: q.before, limit: q.limit })}`;
|
|
140
162
|
},
|
|
163
|
+
candlesMany: (q ) => {
|
|
164
|
+
if (q.ids.length < 1 || q.ids.length > CANDLES_MANY_IDS_MAX) throw new RangeError(`1..${CANDLES_MANY_IDS_MAX} ids`);
|
|
165
|
+
return `/floor-amm/candles/many${query({ ids: q.ids, interval: q.interval, before: q.before, limit: q.limit })}`;
|
|
166
|
+
},
|
|
141
167
|
walletTrades: (w , q = {}) => walletPath(w, `/trades${query({ limit: q.limit, before: q.before, launch: q.launch })}`),
|
|
142
168
|
|
|
143
169
|
tonActivity: (w , q = {}) => walletPath(w, `/ton-activity${query({ limit: q.limit, before: q.before })}`),
|
package/dist/indexer/read.js
CHANGED
|
@@ -56,6 +56,7 @@ export const readFloorRouted = (get ) => readRoute(g
|
|
|
56
56
|
|
|
57
57
|
export const readEvents = (get , fromBlock , toBlock ) => readRoute(get, indexerPath.events(fromBlock, toBlock), B.EVENTS);
|
|
58
58
|
|
|
59
|
+
export const readLaunchLists = (get , q ) => readRoute(get, indexerPath.launchLists(q), B.LAUNCH_LISTS);
|
|
59
60
|
export const readLaunches = (get , q = {}) => readRoute(get, indexerPath.launches(q), B.LAUNCHES);
|
|
60
61
|
|
|
61
62
|
export const readLaunchSearch = (get , q ) => readRoute(get, indexerPath.search(q), B.LAUNCH_SEARCH);
|
|
@@ -93,6 +94,8 @@ export const readMarks = (get , id , q = {})
|
|
|
93
94
|
export const readPrice = (get , id ) => readRoute(get, indexerPath.price(id), B.PRICE);
|
|
94
95
|
|
|
95
96
|
export const readCandles = (get , q ) => readRoute(get, indexerPath.candles(q), B.CANDLES);
|
|
97
|
+
|
|
98
|
+
export const readCandlesMany = (get , q ) => readRoute(get, indexerPath.candlesMany(q), B.CANDLES_MANY);
|
|
96
99
|
export const readCandleBundle = (get , id , q = {}) => readRoute(get, indexerPath.candleBundle(id, q), B.CANDLE_BUNDLE);
|
|
97
100
|
export const readHighs = (get , id , q = {}) => readRoute(get, indexerPath.highs(id, q), B.HIGHS);
|
|
98
101
|
|
package/dist/v2/devbuy.js
CHANGED
|
@@ -18,18 +18,20 @@ export function teamSlotWallets(slot ) {
|
|
|
18
18
|
|
|
19
19
|
export const impactBps = (before , after ) => (before === 0n ? 0n : ((after - before) * 10_000n) / before);
|
|
20
20
|
|
|
21
|
-
export function devBuyFromTrade(t , team , ctx
|
|
21
|
+
export function devBuyFromTrade(t , team , ctx = {}) {
|
|
22
22
|
if (!t.isBuy) return null;
|
|
23
|
+
|
|
24
|
+
const person = ctx.buyer ?? t.trader;
|
|
23
25
|
let role = null;
|
|
24
26
|
if (t.kind === TRADE_KIND_TEAM_BUY || ctx.teamBuy) role = "team_buy";
|
|
25
27
|
else if (t.kind === TRADE_KIND_TEAM_SHARE_BUY || ctx.teamShareBuy) role = "team_share_buy";
|
|
26
|
-
else if (
|
|
27
|
-
else if (teamSlotWallets(team.teamSlot).includes(
|
|
28
|
+
else if (person === team.creator) role = "creator";
|
|
29
|
+
else if (teamSlotWallets(team.teamSlot).includes(person)) role = "team_member";
|
|
28
30
|
if (role === null) return null;
|
|
29
31
|
const priceBeforeX64 = priceX64(t.sqrtBefore);
|
|
30
32
|
const priceAfterX64 = priceX64(t.sqrtAfter);
|
|
31
33
|
return {
|
|
32
|
-
launch: t.launch, trader:
|
|
34
|
+
launch: t.launch, trader: person, role, quoteIn: t.quoteGross - t.refund, tokens: t.tokens, priceBeforeX64, priceAfterX64,
|
|
33
35
|
impactBps: impactBps(priceBeforeX64, priceAfterX64), slot: t.slot,
|
|
34
36
|
};
|
|
35
37
|
}
|
package/dist/v2/presetRowEvm.js
CHANGED
|
@@ -5,6 +5,7 @@ import { bytesToHex, decodeAbi, encodeCall, hexToBytes } from "../evm/abi.js";
|
|
|
5
5
|
import { ROW_LEN, decodeRowV2 } from "../math/v2/preset.js";
|
|
6
6
|
|
|
7
7
|
import { evmSignature } from "../generated/index.js";
|
|
8
|
+
import { MULTICALL3_ADDRESS, aggregate3Call, decodeAggregate3Result } from "../evm/multicall.js";
|
|
8
9
|
|
|
9
10
|
export const PRESET_ROW_VIEW_EVM = { sig: evmSignature("presetRow"), ret: ["(uint8,bool,bool,uint32,bytes32,bytes)"] } ;
|
|
10
11
|
export const NEXT_PRESET_ID_VIEW_EVM = { sig: evmSignature("nextPresetId"), ret: ["uint8"] } ;
|
|
@@ -37,9 +38,27 @@ export function presetMenuV2(rows )
|
|
|
37
38
|
.map((r) => ({ id: r.id, version: r.version, rowHash: bytesToHex(r.rowHash), row: decodeRowV2(r.row) }));
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
const PRESET_MENU_BATCH = 100;
|
|
42
|
+
|
|
43
|
+
export async function readPresetMenuEvmV2(
|
|
44
|
+
rpc , amm , opts = {},
|
|
45
|
+
) {
|
|
41
46
|
const next = decodeNextPresetIdEvmV2(await rpc.ethCall(amm, nextPresetIdCallV2()));
|
|
42
47
|
const ids = Array.from({ length: Math.max(0, next - 1) }, (_, i) => i + 1).filter((id) => id !== RETIRED_ID);
|
|
43
|
-
|
|
48
|
+
if (opts.multicall === null) {
|
|
49
|
+
return presetMenuV2(await Promise.all(ids.map(async (id) => decodePresetRowEvmV2(await rpc.ethCall(amm, presetRowCallV2(id))))));
|
|
50
|
+
}
|
|
51
|
+
const multicall = opts.multicall ?? MULTICALL3_ADDRESS;
|
|
52
|
+
const chunks = [];
|
|
53
|
+
for (let i = 0; i < ids.length; i += PRESET_MENU_BATCH) chunks.push(ids.slice(i, i + PRESET_MENU_BATCH));
|
|
54
|
+
const rows = (await Promise.all(chunks.map(async (chunk) => {
|
|
55
|
+
const call = aggregate3Call(chunk.map((id) => ({ target: amm, allowFailure: true, callData: presetRowCallV2(id) })), multicall);
|
|
56
|
+
const res = decodeAggregate3Result(await rpc.ethCall(call.to, call.data));
|
|
57
|
+
if (res.length !== chunk.length) throw new RangeError(`aggregate3: ${res.length} results, ${chunk.length} calls`);
|
|
58
|
+
return res.map((r, i) => {
|
|
59
|
+
if (!r.success) throw new Error(`presetRow(${chunk[i]}) failed: ${r.returnData}`);
|
|
60
|
+
return decodePresetRowEvmV2(r.returnData);
|
|
61
|
+
});
|
|
62
|
+
}))).flat();
|
|
44
63
|
return presetMenuV2(rows);
|
|
45
64
|
}
|
package/docs/aggregator.md
CHANGED
|
@@ -51,11 +51,33 @@ const call = evmRouteCallV2(q, { router, to: recipient, deadline });
|
|
|
51
51
|
// { to, data, ... }: send it from the trader's wallet
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
## Pay with another coin (EVM zap)
|
|
55
|
+
|
|
56
|
+
A buyer who holds the native coin, or an ERC-20 that is not the launch's quote, buys through a FloorZap, which swaps into the quote and buys in one transaction.
|
|
57
|
+
|
|
58
|
+
- Addresses: `FLOOR_ZAP_ADDRESSES` (`@floorlaunchpad/sdk/evm/chains`) holds the deployed zap per chain and router slot, 15 instances on 8 chains. Each `EVM_CHAINS` zap row carries its own `zap`, `null` where that slot is not deployed. Keep no copy of your own.
|
|
59
|
+
- Swap calldata: `zapSwapData` (`@floorlaunchpad/sdk/evm/zap`) builds the zap's `swapData`. The input is the native coin (the default) or an ERC-20 (`input: "token"`). The output is the launch's ERC-20 quote (the default) or, for a launch quoted in the native coin, the native coin (`output: "native"`).
|
|
60
|
+
- A Universal Router fork row passes that row's `urFork` (`"uniswap"`, `"aerodrome"`, `"pancake"` or `"ramses"`). Uniswap v4 is one pool given as `route.v4`. A native-input Universal Router swap ends with a `SWEEP`, so anything the swap did not spend goes back to the zap, which refunds it.
|
|
61
|
+
- Bridged buys: `buyHookNative` (in `src/evm/squid.ts`) builds the destination-chain hook calls. Pass the launch's `quote`. For an ERC-20 quote the hook adds a third call that passes the quote refund on to the user. Absent or address(0), it is the two calls of 0.4.0.
|
|
62
|
+
|
|
63
|
+
## FloorRouter addresses (EVM)
|
|
64
|
+
|
|
65
|
+
`evmRouteCallV2` takes the FloorRouter's address as `router`. The SDK books one per chain and zap slot: `FLOOR_ROUTER_ADDRESSES` and each zap row's `floorRouter` (`@floorlaunchpad/sdk/evm/chains`), the same address for a slot on every chain that has it. They are derived ahead of the routers' deploy, so an address is usable only once it has code on that chain. Before then a call to it still succeeds and buys nothing, and a native-in buy's coin goes to the empty address and is lost. Check it first (`getCode` answering "0x" or `undefined` is no code):
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { FLOOR_ROUTER_ADDRESSES } from "@floorlaunchpad/sdk/evm/chains";
|
|
69
|
+
import { assertFloorRouterLive } from "@floorlaunchpad/sdk/evm/router";
|
|
70
|
+
|
|
71
|
+
const router = await assertFloorRouterLive({ getCode: (a) => rpc.getCode(a) }, { chain: "base", slot: "uniswap-ur" });
|
|
72
|
+
// throws while the router has no code; otherwise pass `router` to evmRouteCallV2
|
|
73
|
+
```
|
|
74
|
+
|
|
54
75
|
## Things to know
|
|
55
76
|
|
|
56
77
|
- The SDK never sends or signs. It returns instructions or calldata.
|
|
57
78
|
- Fees are added on top of the amount in and come out of the quote you build the call from. Do not subtract them again.
|
|
58
79
|
- Every launch trades from its first block and neither buys nor sells can be paused. A hop that fails does so because of the amount or the slippage bound, not a switch.
|
|
59
80
|
- Amounts are `bigint` in the coin's smallest unit on both chains.
|
|
81
|
+
- A failed EVM call decodes with `decodeEvmProgramError` (`@floorlaunchpad/sdk/errors`), which also knows the five errors the contracts' math libraries revert with: `PriceOrder()`, `ZeroLiquidity()`, `SqrtRange()`, `Zero()` and `VaultShareOutOfRange()`.
|
|
60
82
|
|
|
61
83
|
See also: [README](../README.md), [bot guide](bot.md) for reading launches to build your pool list.
|
package/docs/bot.md
CHANGED
|
@@ -55,6 +55,14 @@ Each candle carries `floorX64`, the floor at the bucket's close, in the same Q64
|
|
|
55
55
|
`null` where a bucket has none, and absent from an indexer older than this build. Use the launch's own `floorX64` for
|
|
56
56
|
that candle then. [floor-line.md](floor-line.md) shows how to draw it.
|
|
57
57
|
|
|
58
|
+
### Many launches in one request
|
|
59
|
+
|
|
60
|
+
`readLaunchLists(get, { quotes, cursors })` returns one `launches` page per quote coin (up to 16) in one answer, each list resumed with its own cursor (`"-"` asks a first page). `readCandlesMany(get, { ids, interval })` returns the newest candles of up to 40 launches at once. Both are in `@floorlaunchpad/sdk/indexer/read`; the limits are in [cursor-pages.md](cursor-pages.md).
|
|
61
|
+
|
|
62
|
+
### Dev buys through a zap or router
|
|
63
|
+
|
|
64
|
+
A buy through a zap or a router has the contract as the trade's `trader`. Pass the person that contract's own event names as `ctx.buyer` to `devBuyFromTrade` (`@floorlaunchpad/sdk/v2/devbuy`), and a creator's or team member's buy through it counts as a dev buy, with that person as `trader`. The trade's recipient alone never names one.
|
|
65
|
+
|
|
58
66
|
## Follow the live stream
|
|
59
67
|
|
|
60
68
|
```ts
|
package/docs/cursor-pages.md
CHANGED
|
@@ -22,6 +22,8 @@ newest page. Asked with none of these, each route answers its whole list in one
|
|
|
22
22
|
| `search?q=` | `readLaunchSearch` | `cursor` | `SEARCH_PAGE_DEFAULT` (12) | `SEARCH_PAGE_MAX` (100) |
|
|
23
23
|
| `wallets/<w>/positions`, `locks`, `claims`, `roles/<w>`, `referrals/<w>/people` | `readPositions`, `readWalletLocks`, `readClaimHistory`, `readRoles`, `readPeople` | `cursor` | `WALLET_PAGE_DEFAULT` (100) | `WALLET_PAGE_MAX` (500) |
|
|
24
24
|
| `wallets/<w>/inbox` | `readInbox` | `before` | `INBOX_PAGE_DEFAULT` (100) | `INBOX_PAGE_MAX` (500) |
|
|
25
|
+
| `launch-lists` (up to 16 quotes) | `readLaunchLists` | `cursors`, one per quote (`"-"` = its first page) | 100 per list | `limit` × quotes ≤ 1,000 rows |
|
|
26
|
+
| `candles/many` (up to 40 launches) | `readCandlesMany` | `before` | 1,000 candles per launch | `limit` × ids ≤ 40,000 candles |
|
|
25
27
|
|
|
26
28
|
No request answers every launch: a bare `launches` is one page of 100. The list body also carries `cursors` (the cursor
|
|
27
29
|
after each row) and `keys` (each row's ranked key); `launches` takes a `preset` filter.
|
package/docs/frontend.md
CHANGED
|
@@ -24,6 +24,8 @@ Use the routing functions in [docs/aggregator.md](aggregator.md). For a single l
|
|
|
24
24
|
|
|
25
25
|
- Route modules in `src/route` and `src/v2/route.ts` contain no host names, so a strict content security policy does not trip on them. Anything that talks to a hosted service is in `route-jupiter.ts` and is opt-in.
|
|
26
26
|
- Keep the quote fresh: re-quote when the user changes the amount and just before they sign.
|
|
27
|
+
- A buy paid in another coin goes through the chain's FloorZap: take its address from the zap row's `zap` (`FLOOR_ZAP_ADDRESSES`, `@floorlaunchpad/sdk/evm/chains`) and its swap from `zapSwapData`; [aggregator.md](aggregator.md) has the details.
|
|
28
|
+
- The create page's preset menu on EVM: `readPresetMenuEvmV2` (`@floorlaunchpad/sdk/v2/presetRowEvm`) reads the rows through one Multicall3 `aggregate3` per 100 ids. Pass `{ multicall }` for another Multicall3 address, or `{ multicall: null }` on a chain without one (one call per id). A row that fails throws; the menu never has a gap.
|
|
27
29
|
- Chain choice happens once, at the edge. Past that point the same quote and build calls work on both chains.
|
|
28
30
|
|
|
29
31
|
See also: [README](../README.md), [wallet guide](wallet.md).
|
package/docs/wallet.md
CHANGED
|
@@ -30,6 +30,8 @@ import { decodeErrorV2 } from "@floorlaunchpad/sdk/v2/evm";
|
|
|
30
30
|
const name = decodeErrorV2(revertData); // the custom error's name, or null
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
`decodeEvmProgramError` (`@floorlaunchpad/sdk/errors`) returns the same name with the module and code, and also knows five errors from the contracts' math libraries that the ABI does not list: `PriceOrder()`, `ZeroLiquidity()`, `SqrtRange()`, `Zero()` and `VaultShareOutOfRange()`.
|
|
34
|
+
|
|
33
35
|
Show the name and your own plain wording for it. The SDK gives you the identifier, not a sentence.
|
|
34
36
|
|
|
35
37
|
## Claim
|