@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.
- package/CHANGELOG.md +84 -0
- package/LICENSE +201 -60
- package/README.md +45 -24
- package/dist/abi/evm-event-names.js +12 -0
- package/dist/abi/evm.gen.js +130 -0
- package/dist/abi/functions.gen.js +144 -0
- package/dist/abi/index.js +17 -0
- package/dist/abi/solana.gen.js +128 -0
- package/dist/burn.js +21 -0
- package/dist/client/evm/index.js +191 -0
- package/dist/client/index.js +19 -0
- package/dist/client/solana/index.js +259 -0
- package/dist/client/types.js +5 -0
- package/dist/codec.js +77 -0
- package/dist/config/codeHash.js +9 -0
- package/dist/config/generated.js +746 -0
- package/dist/config/index.js +49 -0
- package/dist/config/registry.gen.js +118 -0
- package/dist/config/solana-genesis.js +7 -0
- package/dist/ed25519.js +31 -0
- package/dist/errors.js +249 -0
- package/dist/events/index.js +40 -0
- package/dist/events/types.gen.js +3 -0
- package/dist/evm/abi.js +283 -0
- package/dist/evm/balances.js +26 -0
- package/dist/evm/chains.js +144 -0
- package/dist/evm/floor/abi.gen.js +195 -0
- package/dist/evm/floor/calls.js +230 -0
- package/dist/evm/floor/create.js +49 -0
- package/dist/evm/floor/events.js +41 -0
- package/dist/evm/floor/iface.js +44 -0
- package/dist/evm/items.js +209 -0
- package/dist/evm/keccak.js +118 -0
- package/dist/evm/multicall.js +30 -0
- package/dist/evm/router.js +184 -0
- package/dist/evm/zap.js +128 -0
- package/dist/fixtures.js +53 -0
- package/dist/generated/index.js +28 -0
- package/dist/generated/interface.gen.js +146 -0
- package/dist/handle.js +22 -0
- package/dist/index.js +91 -7
- package/dist/indexer/bodies.js +473 -0
- package/dist/indexer/client.js +104 -0
- package/dist/indexer/contract.js +349 -0
- package/dist/indexer/decode.js +97 -0
- package/dist/indexer/partners.js +100 -0
- package/dist/indexer/paths.js +127 -0
- package/dist/indexer/read.js +109 -0
- package/dist/indexer/stream.js +71 -0
- package/dist/lock.js +16 -0
- package/dist/math/fixed.js +154 -0
- package/dist/math/genesis.js +39 -0
- package/dist/math/index.js +20 -0
- package/dist/math/u256.js +49 -0
- package/dist/math/v2/ask.js +162 -0
- package/dist/math/v2/book.js +607 -0
- package/dist/math/v2/circulating.js +62 -0
- package/dist/math/v2/create.js +122 -0
- package/dist/math/v2/display.js +208 -0
- package/dist/math/v2/error.js +17 -0
- package/dist/math/v2/feasibility.js +174 -0
- package/dist/math/v2/fees.js +121 -0
- package/dist/math/v2/holders.js +105 -0
- package/dist/math/v2/milestones.js +40 -0
- package/dist/math/v2/pow.js +69 -0
- package/dist/math/v2/preset.js +151 -0
- package/dist/math/v2/receipt.js +108 -0
- package/dist/math/v2/relay.js +217 -0
- package/dist/math/v2/rows.js +365 -0
- package/dist/math/v2/split.js +111 -0
- package/dist/math/v2/sqrt.js +84 -0
- package/dist/math/v2/supply.js +21 -0
- package/dist/math/v2/team.js +75 -0
- package/dist/math/v2/trade.js +126 -0
- package/dist/math/v2/wide.js +51 -0
- package/dist/quote.js +6 -0
- package/dist/registryPrice.js +23 -0
- package/dist/route/edge-jupiter.js +42 -0
- package/dist/route/edge.js +11 -0
- package/dist/route/graph.js +51 -0
- package/dist/route/path.js +75 -0
- package/dist/route/quote.js +15 -0
- package/dist/route-jupiter.js +35 -0
- package/dist/route.js +8 -0
- package/dist/sha256.js +61 -0
- package/dist/solana/alt.js +18 -0
- package/dist/solana/floor/accounts.js +390 -0
- package/dist/solana/floor/borsh.js +66 -0
- package/dist/solana/floor/create.js +65 -0
- package/dist/solana/floor/events.js +140 -0
- package/dist/solana/floor/genesis.js +91 -0
- package/dist/solana/floor/genesisList.js +68 -0
- package/dist/solana/floor/instructions.js +435 -0
- package/dist/solana/floor/metadata.js +198 -0
- package/dist/solana/floor/mint.js +206 -0
- package/dist/solana/floor/program.js +64 -0
- package/dist/solana/floor/registry.js +83 -0
- package/dist/solana/instruction.js +49 -0
- package/dist/solana/pda.js +88 -0
- package/dist/solana/tx.js +138 -0
- package/dist/v2/burnPreview.js +35 -0
- package/dist/v2/circulating.js +11 -0
- package/dist/v2/claimAllEvm.js +70 -0
- package/dist/v2/claims-evm.js +120 -0
- package/dist/v2/claims.js +218 -0
- package/dist/v2/dead.js +21 -0
- package/dist/v2/devbuy.js +37 -0
- package/dist/v2/events.js +115 -0
- package/dist/v2/evm.js +299 -0
- package/dist/v2/evmReads.js +76 -0
- package/dist/v2/genesis.js +76 -0
- package/dist/v2/layouts.js +217 -0
- package/dist/v2/market-evm.js +74 -0
- package/dist/v2/presetRowEvm.js +45 -0
- package/dist/v2/press.js +106 -0
- package/dist/v2/quoteMint.js +52 -0
- package/dist/v2/receipt-tx.js +149 -0
- package/dist/v2/route-alt.js +114 -0
- package/dist/v2/route.js +389 -0
- package/dist/v2/solana.js +391 -0
- package/dist/v2/solanaSettle.js +97 -0
- package/dist/v2/tx/evm.js +126 -0
- package/dist/v2/tx/genesis.js +47 -0
- package/dist/v2/tx/index.js +5 -0
- package/dist/v2/tx/solana.js +118 -0
- package/dist/v2/types.js +13 -0
- package/docs/aggregator.md +61 -0
- package/docs/bot.md +50 -0
- package/docs/frontend.md +29 -0
- package/docs/wallet.md +54 -0
- package/package.json +428 -32
- package/src/abi/evm-event-names.ts +12 -0
- package/src/abi/evm.gen.ts +139 -0
- package/src/abi/functions.gen.ts +154 -0
- package/src/abi/index.ts +30 -0
- package/src/abi/solana.gen.ts +138 -0
- package/src/burn.ts +37 -0
- package/src/client/evm/index.ts +199 -0
- package/src/client/index.ts +23 -0
- package/src/client/solana/index.ts +260 -0
- package/src/client/types.ts +162 -0
- package/src/codec.ts +77 -0
- package/src/config/codeHash.ts +9 -0
- package/src/config/generated.ts +746 -0
- package/src/config/index.ts +91 -0
- package/src/config/registry.gen.ts +118 -0
- package/src/config/solana-genesis.ts +7 -0
- package/src/ed25519.ts +31 -0
- package/src/errors.ts +270 -0
- package/src/events/index.ts +44 -0
- package/src/events/types.gen.ts +831 -0
- package/src/evm/abi.ts +292 -0
- package/src/evm/balances.ts +26 -0
- package/src/evm/chains.ts +167 -0
- package/src/evm/floor/abi.gen.ts +195 -0
- package/src/evm/floor/calls.ts +247 -0
- package/src/evm/floor/create.ts +68 -0
- package/src/evm/floor/events.ts +51 -0
- package/src/evm/floor/iface.ts +45 -0
- package/src/evm/items.ts +252 -0
- package/src/evm/keccak.ts +118 -0
- package/src/evm/multicall.ts +43 -0
- package/src/evm/router.ts +209 -0
- package/src/evm/zap.ts +152 -0
- package/src/fixtures.ts +53 -0
- package/src/generated/index.ts +29 -0
- package/src/generated/interface.gen.ts +153 -0
- package/src/handle.ts +22 -0
- package/src/index.ts +91 -6
- package/src/indexer/bodies.ts +528 -0
- package/src/indexer/client.ts +178 -0
- package/src/indexer/contract.ts +410 -0
- package/src/indexer/decode.ts +109 -0
- package/src/indexer/partners.ts +109 -0
- package/src/indexer/paths.ts +190 -0
- package/src/indexer/read.ts +119 -0
- package/src/indexer/stream.ts +83 -0
- package/src/lock.ts +16 -0
- package/src/math/fixed.ts +154 -0
- package/src/math/genesis.ts +39 -0
- package/src/math/index.ts +24 -0
- package/src/math/u256.ts +49 -0
- package/src/math/v2/ask.ts +218 -0
- package/src/math/v2/book.ts +660 -0
- package/src/math/v2/circulating.ts +69 -0
- package/src/math/v2/create.ts +139 -0
- package/src/math/v2/display.ts +250 -0
- package/src/math/v2/error.ts +19 -0
- package/src/math/v2/feasibility.ts +200 -0
- package/src/math/v2/fees.ts +121 -0
- package/src/math/v2/holders.ts +124 -0
- package/src/math/v2/milestones.ts +51 -0
- package/src/math/v2/pow.ts +71 -0
- package/src/math/v2/preset.ts +189 -0
- package/src/math/v2/receipt.ts +162 -0
- package/src/math/v2/relay.ts +235 -0
- package/src/math/v2/rows.ts +412 -0
- package/src/math/v2/split.ts +160 -0
- package/src/math/v2/sqrt.ts +86 -0
- package/src/math/v2/supply.ts +27 -0
- package/src/math/v2/team.ts +75 -0
- package/src/math/v2/trade.ts +145 -0
- package/src/math/v2/wide.ts +52 -0
- package/src/quote.ts +6 -0
- package/src/registryPrice.ts +28 -0
- package/src/route/edge-jupiter.ts +71 -0
- package/src/route/edge.ts +22 -0
- package/src/route/graph.ts +77 -0
- package/src/route/path.ts +84 -0
- package/src/route/quote.ts +46 -0
- package/src/route-jupiter.ts +36 -0
- package/src/route.ts +8 -0
- package/src/sha256.ts +61 -0
- package/src/solana/alt.ts +25 -0
- package/src/solana/floor/accounts.ts +393 -0
- package/src/solana/floor/borsh.ts +66 -0
- package/src/solana/floor/create.ts +89 -0
- package/src/solana/floor/events.ts +147 -0
- package/src/solana/floor/genesis.ts +111 -0
- package/src/solana/floor/genesisList.ts +75 -0
- package/src/solana/floor/instructions.ts +491 -0
- package/src/solana/floor/metadata.ts +246 -0
- package/src/solana/floor/mint.ts +242 -0
- package/src/solana/floor/program.ts +64 -0
- package/src/solana/floor/registry.ts +96 -0
- package/src/solana/instruction.ts +61 -0
- package/src/solana/pda.ts +91 -0
- package/src/solana/tx.ts +143 -0
- package/src/v2/burnPreview.ts +52 -0
- package/src/v2/circulating.ts +22 -0
- package/src/v2/claimAllEvm.ts +97 -0
- package/src/v2/claims-evm.ts +179 -0
- package/src/v2/claims.ts +288 -0
- package/src/v2/dead.ts +21 -0
- package/src/v2/devbuy.ts +55 -0
- package/src/v2/events.ts +131 -0
- package/src/v2/evm.ts +349 -0
- package/src/v2/evmReads.ts +121 -0
- package/src/v2/genesis.ts +80 -0
- package/src/v2/layouts.ts +219 -0
- package/src/v2/market-evm.ts +95 -0
- package/src/v2/presetRowEvm.ts +54 -0
- package/src/v2/press.ts +124 -0
- package/src/v2/quoteMint.ts +63 -0
- package/src/v2/receipt-tx.ts +251 -0
- package/src/v2/route-alt.ts +114 -0
- package/src/v2/route.ts +494 -0
- package/src/v2/solana.ts +439 -0
- package/src/v2/solanaSettle.ts +117 -0
- package/src/v2/tx/evm.ts +152 -0
- package/src/v2/tx/genesis.ts +66 -0
- package/src/v2/tx/index.ts +5 -0
- package/src/v2/tx/solana.ts +140 -0
- package/src/v2/types.ts +284 -0
- package/dist/adapter.d.ts +0 -28
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -2
- package/dist/adapter.js.map +0 -1
- package/dist/chain.d.ts +0 -23
- package/dist/chain.d.ts.map +0 -1
- package/dist/chain.js +0 -25
- package/dist/chain.js.map +0 -1
- package/dist/client.d.ts +0 -26
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -43
- package/dist/client.js.map +0 -1
- package/dist/dex-adapter.d.ts +0 -228
- package/dist/dex-adapter.d.ts.map +0 -1
- package/dist/dex-adapter.js +0 -407
- package/dist/dex-adapter.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/quotes.d.ts +0 -12
- package/dist/quotes.d.ts.map +0 -1
- package/dist/quotes.gen.d.ts +0 -8
- package/dist/quotes.gen.d.ts.map +0 -1
- package/dist/quotes.gen.js +0 -2170
- package/dist/quotes.gen.js.map +0 -1
- package/dist/quotes.js +0 -24
- package/dist/quotes.js.map +0 -1
- package/dist/types.d.ts +0 -111
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/adapter.ts +0 -20
- package/src/chain.ts +0 -39
- package/src/client.ts +0 -41
- package/src/dex-adapter.ts +0 -477
- package/src/quotes.gen.ts +0 -2170
- package/src/quotes.ts +0 -29
- package/src/types.ts +0 -115
package/dist/evm/abi.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { keccak256 } from "./keccak.js";
|
|
4
|
+
|
|
5
|
+
export class AbiError extends Error {
|
|
6
|
+
constructor(detail ) {
|
|
7
|
+
super(`abi: ${detail}`);
|
|
8
|
+
this.name = "AbiError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function splitTop(s ) {
|
|
13
|
+
const out = [];
|
|
14
|
+
let depth = 0;
|
|
15
|
+
let cur = "";
|
|
16
|
+
for (const ch of s) {
|
|
17
|
+
if (ch === "(") depth++;
|
|
18
|
+
if (ch === ")") depth--;
|
|
19
|
+
if (ch === "," && depth === 0) {
|
|
20
|
+
out.push(cur);
|
|
21
|
+
cur = "";
|
|
22
|
+
} else cur += ch;
|
|
23
|
+
}
|
|
24
|
+
if (cur.length > 0 || out.length > 0) out.push(cur);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function parseType(t ) {
|
|
29
|
+
const s = t.trim();
|
|
30
|
+
if (s.endsWith("]")) {
|
|
31
|
+
const i = s.lastIndexOf("[");
|
|
32
|
+
const n = s.slice(i + 1, -1);
|
|
33
|
+
if (i <= 0 || !/^\d*$/.test(n)) throw new AbiError(`bad array ${s}`);
|
|
34
|
+
return { kind: "array", of: parseType(s.slice(0, i)), length: n === "" ? null : Number(n) };
|
|
35
|
+
}
|
|
36
|
+
if (s.startsWith("(") && s.endsWith(")")) return { kind: "tuple", of: splitTop(s.slice(1, -1)).map(parseType) };
|
|
37
|
+
if (s === "address" || s === "bool" || s === "bytes" || s === "string") return { kind: s };
|
|
38
|
+
const m = /^(u?int)(\d*)$/.exec(s);
|
|
39
|
+
if (m) {
|
|
40
|
+
const bits = m[2] === "" ? 256 : Number(m[2]);
|
|
41
|
+
if (bits % 8 !== 0 || bits < 8 || bits > 256) throw new AbiError(`bad width ${s}`);
|
|
42
|
+
return { kind: m[1] === "uint" ? "uint" : "int", bits };
|
|
43
|
+
}
|
|
44
|
+
const b = /^bytes(\d+)$/.exec(s);
|
|
45
|
+
if (b) {
|
|
46
|
+
const size = Number(b[1]);
|
|
47
|
+
if (size < 1 || size > 32) throw new AbiError(`bad size ${s}`);
|
|
48
|
+
return { kind: "fixedBytes", size };
|
|
49
|
+
}
|
|
50
|
+
throw new AbiError(`unknown type ${s}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function typeString(t ) {
|
|
54
|
+
switch (t.kind) {
|
|
55
|
+
case "uint":
|
|
56
|
+
case "int":
|
|
57
|
+
return `${t.kind}${t.bits}`;
|
|
58
|
+
case "fixedBytes":
|
|
59
|
+
return `bytes${t.size}`;
|
|
60
|
+
case "array":
|
|
61
|
+
return `${typeString(t.of)}[${t.length ?? ""}]`;
|
|
62
|
+
case "tuple":
|
|
63
|
+
return `(${t.of.map(typeString).join(",")})`;
|
|
64
|
+
default:
|
|
65
|
+
return t.kind;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isDynamic(t ) {
|
|
70
|
+
if (t.kind === "bytes" || t.kind === "string") return true;
|
|
71
|
+
if (t.kind === "array") return t.length === null || isDynamic(t.of);
|
|
72
|
+
if (t.kind === "tuple") return t.of.some(isDynamic);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function headSize(t ) {
|
|
77
|
+
if (isDynamic(t)) return 32;
|
|
78
|
+
if (t.kind === "array") return (t.length ) * headSize(t.of);
|
|
79
|
+
if (t.kind === "tuple") return t.of.reduce((a, x) => a + headSize(x), 0);
|
|
80
|
+
return 32;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function hexToBytes(h ) {
|
|
84
|
+
const s = h.startsWith("0x") || h.startsWith("0X") ? h.slice(2) : h;
|
|
85
|
+
if (s.length % 2 !== 0 || /[^0-9a-fA-F]/.test(s)) throw new AbiError(`bad hex ${h}`);
|
|
86
|
+
const out = new Uint8Array(s.length / 2);
|
|
87
|
+
for (let i = 0; i < out.length; i++) out[i] = parseInt(s.slice(2 * i, 2 * i + 2), 16);
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function bytesToHex(b ) {
|
|
92
|
+
let s = "0x";
|
|
93
|
+
for (const x of b) s += x.toString(16).padStart(2, "0");
|
|
94
|
+
return s;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const concat = (parts ) => {
|
|
98
|
+
const out = new Uint8Array(parts.reduce((a, p) => a + p.length, 0));
|
|
99
|
+
let o = 0;
|
|
100
|
+
for (const p of parts) {
|
|
101
|
+
out.set(p, o);
|
|
102
|
+
o += p.length;
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
function word(v ) {
|
|
108
|
+
const out = new Uint8Array(32);
|
|
109
|
+
let x = v;
|
|
110
|
+
for (let i = 31; i >= 0; i--) {
|
|
111
|
+
out[i] = Number(x & 0xffn);
|
|
112
|
+
x >>= 8n;
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const readWord = (d , o ) => {
|
|
118
|
+
if (o + 32 > d.length) throw new AbiError("data too short");
|
|
119
|
+
let v = 0n;
|
|
120
|
+
for (let i = 0; i < 32; i++) v = (v << 8n) | BigInt(d[o + i]);
|
|
121
|
+
return v;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const asBytes = (v ) => (v instanceof Uint8Array ? v : typeof v === "string" ? hexToBytes(v) : (() => { throw new AbiError("expected bytes"); })());
|
|
125
|
+
|
|
126
|
+
const padRight = (b ) => {
|
|
127
|
+
const out = new Uint8Array(Math.ceil(b.length / 32) * 32);
|
|
128
|
+
out.set(b);
|
|
129
|
+
return out;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
function encodeOne(t , v ) {
|
|
133
|
+
switch (t.kind) {
|
|
134
|
+
case "uint": {
|
|
135
|
+
if (typeof v !== "bigint" || v < 0n || v >= 1n << BigInt(t.bits)) throw new AbiError(`uint${t.bits} out of range`);
|
|
136
|
+
return word(v);
|
|
137
|
+
}
|
|
138
|
+
case "int": {
|
|
139
|
+
const lim = 1n << BigInt(t.bits - 1);
|
|
140
|
+
if (typeof v !== "bigint" || v < -lim || v >= lim) throw new AbiError(`int${t.bits} out of range`);
|
|
141
|
+
return word(v < 0n ? (1n << 256n) + v : v);
|
|
142
|
+
}
|
|
143
|
+
case "address": {
|
|
144
|
+
const b = asBytes(v);
|
|
145
|
+
if (b.length !== 20) throw new AbiError("an address is 20 bytes");
|
|
146
|
+
const out = new Uint8Array(32);
|
|
147
|
+
out.set(b, 12);
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
case "bool":
|
|
151
|
+
if (typeof v !== "boolean") throw new AbiError("expected bool");
|
|
152
|
+
return word(v ? 1n : 0n);
|
|
153
|
+
case "fixedBytes": {
|
|
154
|
+
const b = asBytes(v);
|
|
155
|
+
if (b.length !== t.size) throw new AbiError(`bytes${t.size} is ${t.size} bytes`);
|
|
156
|
+
const out = new Uint8Array(32);
|
|
157
|
+
out.set(b);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
case "bytes":
|
|
161
|
+
case "string": {
|
|
162
|
+
const b = t.kind === "string" ? (typeof v === "string" ? new TextEncoder().encode(v) : (() => { throw new AbiError("expected string"); })()) : asBytes(v);
|
|
163
|
+
return concat([word(BigInt(b.length)), padRight(b)]);
|
|
164
|
+
}
|
|
165
|
+
case "array": {
|
|
166
|
+
if (!Array.isArray(v)) throw new AbiError("expected array");
|
|
167
|
+
if (t.length !== null && v.length !== t.length) throw new AbiError(`expected ${t.length} items`);
|
|
168
|
+
const body = encodeSeq(v.map(() => t.of), v);
|
|
169
|
+
return t.length === null ? concat([word(BigInt(v.length)), body]) : body;
|
|
170
|
+
}
|
|
171
|
+
case "tuple": {
|
|
172
|
+
if (!Array.isArray(v) || v.length !== t.of.length) throw new AbiError("tuple arity");
|
|
173
|
+
return encodeSeq(t.of, v);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function encodeSeq(types , values ) {
|
|
179
|
+
if (types.length !== values.length) throw new AbiError(`expected ${types.length} values, got ${values.length}`);
|
|
180
|
+
const heads = [];
|
|
181
|
+
const tails = [];
|
|
182
|
+
let tailOff = types.reduce((a, t) => a + headSize(t), 0);
|
|
183
|
+
types.forEach((t, i) => {
|
|
184
|
+
const e = encodeOne(t, values[i]);
|
|
185
|
+
if (isDynamic(t)) {
|
|
186
|
+
heads.push(word(BigInt(tailOff)));
|
|
187
|
+
tails.push(e);
|
|
188
|
+
tailOff += e.length;
|
|
189
|
+
} else heads.push(e);
|
|
190
|
+
});
|
|
191
|
+
return concat([...heads, ...tails]);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function encodeAbi(types , values ) {
|
|
195
|
+
return encodeSeq(types.map((t) => (typeof t === "string" ? parseType(t) : t)), [...values]);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function decodeOne(t , d , base , at ) {
|
|
199
|
+
const o = isDynamic(t) ? base + Number(readWord(d, at)) : at;
|
|
200
|
+
switch (t.kind) {
|
|
201
|
+
case "uint":
|
|
202
|
+
return readWord(d, o);
|
|
203
|
+
case "int": {
|
|
204
|
+
const w = readWord(d, o);
|
|
205
|
+
return w >= 1n << 255n ? w - (1n << 256n) : w;
|
|
206
|
+
}
|
|
207
|
+
case "address":
|
|
208
|
+
return checksumAddress(bytesToHex(d.slice(o + 12, o + 32)));
|
|
209
|
+
case "bool":
|
|
210
|
+
return readWord(d, o) !== 0n;
|
|
211
|
+
case "fixedBytes":
|
|
212
|
+
return bytesToHex(d.slice(o, o + t.size));
|
|
213
|
+
case "bytes":
|
|
214
|
+
case "string": {
|
|
215
|
+
const n = Number(readWord(d, o));
|
|
216
|
+
if (o + 32 + n > d.length) throw new AbiError("data too short");
|
|
217
|
+
const b = d.slice(o + 32, o + 32 + n);
|
|
218
|
+
return t.kind === "string" ? new TextDecoder().decode(b) : bytesToHex(b);
|
|
219
|
+
}
|
|
220
|
+
case "array": {
|
|
221
|
+
let n = t.length ?? 0;
|
|
222
|
+
let start = o;
|
|
223
|
+
if (t.length === null) {
|
|
224
|
+
n = Number(readWord(d, o));
|
|
225
|
+
start = o + 32;
|
|
226
|
+
}
|
|
227
|
+
return decodeSeq(Array.from({ length: n }, () => t.of), d, start);
|
|
228
|
+
}
|
|
229
|
+
case "tuple":
|
|
230
|
+
return decodeSeq(t.of, d, o);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function decodeSeq(types , d , base ) {
|
|
235
|
+
const out = [];
|
|
236
|
+
let at = base;
|
|
237
|
+
for (const t of types) {
|
|
238
|
+
out.push(decodeOne(t, d, base, at));
|
|
239
|
+
at += headSize(t);
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function decodeAbi(types , data ) {
|
|
245
|
+
return decodeSeq(types.map((t) => (typeof t === "string" ? parseType(t) : t)), typeof data === "string" ? hexToBytes(data) : data, 0);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function parseSignature(sig ) {
|
|
249
|
+
const m = /^([A-Za-z_$][A-Za-z0-9_$]*)\((.*)\)$/.exec(sig.replace(/\s+/g, ""));
|
|
250
|
+
if (!m) throw new AbiError(`bad signature ${sig}`);
|
|
251
|
+
const types = m[2] === "" ? [] : splitTop(m[2]).map(parseType);
|
|
252
|
+
return { name: m[1], types, canonical: `${m[1]}(${types.map(typeString).join(",")})` };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function functionSelector(sig ) {
|
|
256
|
+
return keccak256(new TextEncoder().encode(parseSignature(sig).canonical)).slice(0, 4);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function eventTopic(sig ) {
|
|
260
|
+
return bytesToHex(keccak256(new TextEncoder().encode(parseSignature(sig).canonical)));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function encodeCall(sig , values ) {
|
|
264
|
+
const { types } = parseSignature(sig);
|
|
265
|
+
return concat([functionSelector(sig), encodeSeq(types, [...values])]);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function checksumAddress(a ) {
|
|
269
|
+
const b = hexToBytes(a);
|
|
270
|
+
if (b.length !== 20) throw new AbiError("an address is 20 bytes");
|
|
271
|
+
const lower = bytesToHex(b).slice(2);
|
|
272
|
+
const h = bytesToHex(keccak256(new TextEncoder().encode(lower))).slice(2);
|
|
273
|
+
let out = "0x";
|
|
274
|
+
for (let i = 0; i < 40; i++) out += parseInt(h[i], 16) >= 8 ? lower[i].toUpperCase() : lower[i];
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function create2Address(p ) {
|
|
279
|
+
const salt = typeof p.salt === "string" ? hexToBytes(p.salt) : p.salt;
|
|
280
|
+
if (salt.length !== 32) throw new AbiError("a salt is 32 bytes");
|
|
281
|
+
const h = p.initCodeHash !== undefined ? asBytes(p.initCodeHash) : keccak256(asBytes(p.initCode ?? new Uint8Array()));
|
|
282
|
+
return checksumAddress(bytesToHex(keccak256(concat([Uint8Array.of(0xff), hexToBytes(p.deployer), salt, h])).slice(12)));
|
|
283
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { checksumAddress, decodeAbi, encodeCall, bytesToHex } from "./abi.js";
|
|
4
|
+
import { MULTICALL3_ADDRESS, aggregate3Call, decodeAggregate3Result } from "./multicall.js";
|
|
5
|
+
|
|
6
|
+
import { evmSignature } from "../generated/index.js";
|
|
7
|
+
|
|
8
|
+
const BALANCE_OF = evmSignature("balanceOf");
|
|
9
|
+
|
|
10
|
+
export const balanceOfData = (owner ) => bytesToHex(encodeCall(BALANCE_OF, [checksumAddress(owner)]));
|
|
11
|
+
|
|
12
|
+
export function balancesCall(owner , tokens , multicall = MULTICALL3_ADDRESS) {
|
|
13
|
+
const data = balanceOfData(owner);
|
|
14
|
+
return aggregate3Call(tokens.map((t) => ({ target: t, allowFailure: true, callData: data })), multicall);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function holdersBalanceCall(token , owners , multicall = MULTICALL3_ADDRESS) {
|
|
18
|
+
return aggregate3Call(owners.map((o) => ({ target: token, allowFailure: true, callData: balanceOfData(o) })), multicall);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function decodeBalances(data ) {
|
|
22
|
+
return decodeAggregate3Result(data).map((r) => {
|
|
23
|
+
if (!r.success || r.returnData.length < 2 + 64) return null;
|
|
24
|
+
return (decodeAbi(["uint256"], r.returnData) )[0];
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { bytesToHex, checksumAddress, create2Address, encodeAbi, hexToBytes } from "./abi.js";
|
|
4
|
+
import { keccak256 } from "./keccak.js";
|
|
5
|
+
|
|
6
|
+
import { CHAIN_REGISTRY, EVM_CHAIN_SLUGS } from "../config/registry.gen.js";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
function strict(a ) {
|
|
16
|
+
const c = checksumAddress(a);
|
|
17
|
+
const body = a.slice(2);
|
|
18
|
+
if (body !== body.toLowerCase() && body !== body.toUpperCase() && a !== c) throw new RangeError(`${a} is not its EIP-55 checksum ${c}`);
|
|
19
|
+
return c;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const r = (slot , amm , router , family , confidence , optional = false, forkEncoding = false) => ({
|
|
23
|
+
slot,
|
|
24
|
+
amm,
|
|
25
|
+
router: strict(router),
|
|
26
|
+
family,
|
|
27
|
+
confidence,
|
|
28
|
+
optional,
|
|
29
|
+
...(forkEncoding ? { forkEncoding } : {}),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const UNISWAP_UR = "uniswap-ur";
|
|
33
|
+
|
|
34
|
+
const ROUTES = {
|
|
35
|
+
ethereum: {
|
|
36
|
+
wrappedNative: strict("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
|
37
|
+
zapRouters: [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x4C82D1fBFe28C977cBB58D8C7FF8FCF9F70a2cCA", "uniswap-ur", "HIGH")],
|
|
38
|
+
notes: [],
|
|
39
|
+
},
|
|
40
|
+
base: {
|
|
41
|
+
wrappedNative: strict("0x4200000000000000000000000000000000000006"),
|
|
42
|
+
zapRouters: [
|
|
43
|
+
r("aerodrome-ur", "Aerodrome V1 + Slipstream", "0xC5b6786D7B64767D775877b0B6A319AD946B11B5", "uniswap-ur", "HIGH", false, true),
|
|
44
|
+
r(UNISWAP_UR, "Uniswap v2/v3/v4", "0xFdf682F51FE81Aa4898F0AE2163d8A55c127fbC7", "uniswap-ur", "HIGH"),
|
|
45
|
+
r("pancake-ur", "PancakeSwap V3 / Infinity", "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB", "uniswap-ur", "HIGH", true, true),
|
|
46
|
+
],
|
|
47
|
+
notes: [],
|
|
48
|
+
},
|
|
49
|
+
bsc: {
|
|
50
|
+
wrappedNative: strict("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"),
|
|
51
|
+
zapRouters: [
|
|
52
|
+
r("pancake-ur", "PancakeSwap V2 / V3 / Infinity", "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB", "uniswap-ur", "HIGH", false, true),
|
|
53
|
+
r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH"),
|
|
54
|
+
],
|
|
55
|
+
notes: ["⚠ 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD is Uniswap's UR v1.2, NOT PancakeSwap's: never use it as Pancake's."],
|
|
56
|
+
},
|
|
57
|
+
arbitrum: {
|
|
58
|
+
wrappedNative: strict("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"),
|
|
59
|
+
zapRouters: [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH")],
|
|
60
|
+
notes: [],
|
|
61
|
+
},
|
|
62
|
+
hyperevm: {
|
|
63
|
+
maxFloorHops: 2,
|
|
64
|
+
wrappedNative: strict("0x5555555555555555555555555555555555555555"),
|
|
65
|
+
zapRouters: [
|
|
66
|
+
r("prjx", "Project X", "0x1EbDFC75FfE3ba3de61E7138a3E8706aC841Af9B", "v3-router", "MEDIUM–HIGH"),
|
|
67
|
+
r("nest", "nest (CL)", "0xaA26B8e5Cadd04430c32787eCC3AA325e99681e9", "algebra", "HIGH"),
|
|
68
|
+
r("ramses-ur", "Ramses CL V2", "0xc43b33b5DF826A48DAE764817647824ED4f476a7", "uniswap-ur", "MEDIUM", false, true),
|
|
69
|
+
r("hyperswap", "HyperSwap V3", "0x6D99e7f6747AF2cDbB5164b6DD50e40D4fDe1e77", "v3-router02", "HIGH", true),
|
|
70
|
+
],
|
|
71
|
+
notes: ["⚠ Small blocks cap a transaction at 3M gas: a buy that graduates a launch may need a big block."],
|
|
72
|
+
},
|
|
73
|
+
robinhood: {
|
|
74
|
+
wrappedNative: strict("0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73"),
|
|
75
|
+
zapRouters: [
|
|
76
|
+
r(UNISWAP_UR, "Uniswap v2/v3/v4 (+ Fables v4 pools)", "0x8876789976dEcBfCbBbe364623C63652db8C0904", "uniswap-ur", "HIGH"),
|
|
77
|
+
r("ramses-ur", "Ramses", "0xbFbb2BCBc9dfFA029C27A249ae9BE031E1d83b1C", "uniswap-ur", "HIGH", true, true),
|
|
78
|
+
],
|
|
79
|
+
notes: [],
|
|
80
|
+
},
|
|
81
|
+
arc: {
|
|
82
|
+
wrappedNative: null,
|
|
83
|
+
zapRouters: [r(UNISWAP_UR, "Uniswap v4 (native-USDC pools)", "0x4fcA4a51Ab4F23A7447b3284fBd7D73289A89Fb1", "uniswap-ur", "HIGH")],
|
|
84
|
+
notes: [
|
|
85
|
+
"⚠ The native coin is USDC (18 dp at the EVM level; its ERC-20 view 0x3600000000000000000000000000000000000000 has 6 dp and no deposit()).",
|
|
86
|
+
"⚠ 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.",
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const EVM_CHAINS = Object.fromEntries(
|
|
92
|
+
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 ) === false ? { v2DayOne: false } : {}) }]] : [])),
|
|
93
|
+
) ;
|
|
94
|
+
|
|
95
|
+
export const v2DayOneChains = () => Object.values(EVM_CHAINS).filter((c) => c.v2DayOne !== false);
|
|
96
|
+
export const chainById = (chainId ) => Object.values(EVM_CHAINS).find((c) => c.chainId === chainId) ?? null;
|
|
97
|
+
|
|
98
|
+
export const CREATE2_FACTORY = "0x4e59b44847b379578588920cA78FbF26c0B4956C";
|
|
99
|
+
const salt = (s ) => bytesToHex(keccak256(new TextEncoder().encode(s)));
|
|
100
|
+
|
|
101
|
+
export const FLOOR_SALTS = {
|
|
102
|
+
|
|
103
|
+
proxyBootstrap: salt("floor-amm.v2.proxy-bootstrap"),
|
|
104
|
+
|
|
105
|
+
zapDeployer: salt("floor-amm.v2.zap-deployer"),
|
|
106
|
+
|
|
107
|
+
routerDeployer: salt("floor-router.v2.router-deployer"),
|
|
108
|
+
} ;
|
|
109
|
+
|
|
110
|
+
export const FLOOR_AMM_ADDRESS = null;
|
|
111
|
+
|
|
112
|
+
const cat = (...h ) => "0x" + h.map((x) => bytesToHex(hexToBytes(x)).slice(2)).join("");
|
|
113
|
+
const at = (s , init ) => create2Address({ deployer: CREATE2_FACTORY, salt: s, initCode: init });
|
|
114
|
+
|
|
115
|
+
export function floorAmmAddressV2(p ) {
|
|
116
|
+
const bootstrap = at(FLOOR_SALTS.proxyBootstrap, cat(p.code.bootstrap, bytesToHex(encodeAbi(["address"], [p.deployer]))));
|
|
117
|
+
const floorAmm = at(p.proxySalt, cat(p.code.proxy, bytesToHex(encodeAbi(["address", "bytes"], [bootstrap, "0x"]))));
|
|
118
|
+
return { bootstrap, floorAmm };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const tokenImplAddressV2 = (p ) => at(p.salt, p.code);
|
|
122
|
+
|
|
123
|
+
export function zapDeployerAddressV2(p ) {
|
|
124
|
+
return at(FLOOR_SALTS.zapDeployer, cat(p.code, bytesToHex(encodeAbi(["address", "address"], [p.floorAmm, p.authority]))));
|
|
125
|
+
}
|
|
126
|
+
export function routerDeployerAddressV2(p ) {
|
|
127
|
+
return at(FLOOR_SALTS.routerDeployer, cat(p.code, bytesToHex(encodeAbi(["address", "address"], [p.floorAmm, p.authority]))));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function eip1167CreationCode(impl ) {
|
|
131
|
+
const a = impl.toLowerCase().replace(/^0x/, "");
|
|
132
|
+
if (!/^[0-9a-f]{40}$/.test(a)) throw new RangeError("an implementation is a 20-byte address");
|
|
133
|
+
return `0x3d602d80600a3d3981f3363d3d373d3d3d363d73${a}5af43d82803e903d91602b57fd5bf3`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function launchTokenSalt(p ) {
|
|
137
|
+
return p.sameAddressEverywhere
|
|
138
|
+
? bytesToHex(keccak256(encodeAbi(["address", "bytes32"], [p.creator, p.creatorSalt])))
|
|
139
|
+
: bytesToHex(keccak256(encodeAbi(["uint256", "uint256"], [p.chainId, p.id])));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function launchTokenAddress(p ) {
|
|
143
|
+
return create2Address({ deployer: p.floorAmm, salt: launchTokenSalt(p), initCode: eip1167CreationCode(p.tokenImpl) });
|
|
144
|
+
}
|