@floorlaunchpad/sdk 0.3.2 → 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 +94 -0
- package/README.md +16 -0
- package/dist/abi/evm.gen.js +6 -1
- package/dist/abi/solana.gen.js +1 -1
- package/dist/client/evm/index.js +16 -2
- package/dist/client/solana/index.js +31 -14
- package/dist/config/generated.js +26864 -402
- package/dist/config/registry.gen.js +33 -2
- package/dist/evm/chains.js +85 -16
- package/dist/evm/floor/abi.gen.js +1 -1
- package/dist/evm/floor/events.js +9 -1
- package/dist/evm/floor/legacy-events.js +25 -0
- 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 +96 -17
- package/dist/indexer/client.js +36 -14
- package/dist/indexer/contract.js +178 -28
- package/dist/indexer/partners.js +3 -2
- package/dist/indexer/paths.js +87 -29
- package/dist/indexer/read.js +30 -15
- package/dist/indexer/search.js +130 -0
- package/dist/indexer/stack-edge.js +35 -0
- package/dist/indexer/stream.js +70 -23
- package/dist/math/v2/split.js +11 -3
- package/dist/solana/floor/events.js +1 -1
- package/dist/solana/floor/genesis.js +9 -3
- package/dist/solana/floor/instructions.js +14 -5
- package/dist/solana/floor/registry.js +4 -0
- package/dist/v2/devbuy.js +6 -4
- package/dist/v2/presetRowEvm.js +21 -2
- package/dist/v2/solana.js +17 -2
- package/dist/v2/tx/solana.js +1 -1
- package/docs/aggregator.md +22 -0
- package/docs/bot.md +44 -1
- package/docs/cursor-pages.md +58 -0
- package/docs/floor-line.md +9 -4
- package/docs/frontend.md +2 -0
- package/docs/wallet.md +2 -0
- package/examples/floor-line.html +6 -6
- package/package.json +1 -1
- package/src/abi/evm.gen.ts +6 -1
- package/src/abi/solana.gen.ts +1 -1
- package/src/client/evm/index.ts +16 -2
- package/src/client/solana/index.ts +31 -14
- package/src/client/types.ts +1 -1
- package/src/config/generated.ts +26864 -402
- package/src/config/index.ts +9 -2
- package/src/config/registry.gen.ts +33 -2
- package/src/events/types.gen.ts +2 -1
- package/src/evm/chains.ts +94 -15
- package/src/evm/floor/abi.gen.ts +1 -1
- package/src/evm/floor/events.ts +11 -1
- package/src/evm/floor/legacy-events.ts +27 -0
- 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 +106 -17
- package/src/indexer/client.ts +56 -30
- package/src/indexer/contract.ts +197 -29
- package/src/indexer/partners.ts +3 -2
- package/src/indexer/paths.ts +131 -29
- package/src/indexer/read.ts +36 -17
- package/src/indexer/search.ts +138 -0
- package/src/indexer/stack-edge.ts +46 -0
- package/src/indexer/stream.ts +78 -24
- package/src/math/v2/split.ts +11 -3
- package/src/solana/floor/events.ts +1 -1
- package/src/solana/floor/genesis.ts +8 -2
- package/src/solana/floor/instructions.ts +13 -5
- package/src/solana/floor/registry.ts +4 -0
- package/src/v2/devbuy.ts +6 -4
- package/src/v2/presetRowEvm.ts +21 -2
- package/src/v2/solana.ts +20 -3
- package/src/v2/tx/solana.ts +1 -1
|
@@ -110,9 +110,40 @@ export const CHAIN_REGISTRY = [
|
|
|
110
110
|
},
|
|
111
111
|
"finality": "finalized",
|
|
112
112
|
"reorgWindow": 65
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"slug": "elysium",
|
|
116
|
+
"label": "Elysium",
|
|
117
|
+
"family": "evm",
|
|
118
|
+
"v2DayOne": true,
|
|
119
|
+
"chainId": 99901,
|
|
120
|
+
"soakChainId": 99801,
|
|
121
|
+
"native": {
|
|
122
|
+
"name": "Hype",
|
|
123
|
+
"symbol": "HYPE"
|
|
124
|
+
},
|
|
125
|
+
"finality": "safe",
|
|
126
|
+
"reorgWindow": 3400
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"slug": "ton",
|
|
130
|
+
"label": "TON",
|
|
131
|
+
"family": "ton",
|
|
132
|
+
"v2DayOne": false,
|
|
133
|
+
"network": "mainnet",
|
|
134
|
+
"globalId": -239,
|
|
135
|
+
"soakNetwork": "testnet",
|
|
136
|
+
"soakGlobalId": -3,
|
|
137
|
+
"native": {
|
|
138
|
+
"name": "Gram",
|
|
139
|
+
"symbol": "GRAM",
|
|
140
|
+
"decimals": 9
|
|
141
|
+
}
|
|
113
142
|
}
|
|
114
143
|
] ;
|
|
115
144
|
|
|
116
|
-
export const CHAIN_SLUGS = ["solana","ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm"] ;
|
|
145
|
+
export const CHAIN_SLUGS = ["solana","ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm","elysium","ton"] ;
|
|
146
|
+
|
|
147
|
+
export const EVM_CHAIN_SLUGS = ["ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm","elysium"] ;
|
|
117
148
|
|
|
118
|
-
export const
|
|
149
|
+
export const TON_CHAIN_SLUGS = ["ton"] ;
|
package/dist/evm/chains.js
CHANGED
|
@@ -10,8 +10,6 @@ import { CHAIN_REGISTRY, EVM_CHAIN_SLUGS } from "../config/registry.gen.js";
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
13
|
function strict(a ) {
|
|
16
14
|
const c = checksumAddress(a);
|
|
17
15
|
const body = a.slice(2);
|
|
@@ -19,79 +17,150 @@ function strict(a ) {
|
|
|
19
17
|
return c;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
const
|
|
20
|
+
const UR_FORK_OF_SLOT = { "aerodrome-ur": "aerodrome", "pancake-ur": "pancake", "ramses-ur": "ramses" };
|
|
21
|
+
function urForkOf(slot ) {
|
|
22
|
+
const f = UR_FORK_OF_SLOT[slot];
|
|
23
|
+
if (!f) throw new RangeError(`the UR fork row ${slot} names no fork`);
|
|
24
|
+
return f;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const r = (slot , amm , router , family , confidence , optional = false, forkEncoding = false) => ({
|
|
23
28
|
slot,
|
|
24
29
|
amm,
|
|
25
30
|
router: strict(router),
|
|
26
31
|
family,
|
|
27
32
|
confidence,
|
|
28
33
|
optional,
|
|
29
|
-
...(forkEncoding ? { forkEncoding } : {}),
|
|
34
|
+
...(forkEncoding ? { forkEncoding, urFork: urForkOf(slot) } : {}),
|
|
30
35
|
});
|
|
31
36
|
|
|
37
|
+
export const FLOOR_ZAP_ADDRESSES = {
|
|
38
|
+
ethereum: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
|
|
39
|
+
base: {
|
|
40
|
+
"aerodrome-ur": strict("0xD8329A195F26c27A911B5CE697B11947984dc0d1"),
|
|
41
|
+
"uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
|
|
42
|
+
"pancake-ur": strict("0xE4335AaC829a788bb6988A372edfe3Cda41B0931"),
|
|
43
|
+
},
|
|
44
|
+
bsc: {
|
|
45
|
+
"pancake-ur": strict("0xE4335AaC829a788bb6988A372edfe3Cda41B0931"),
|
|
46
|
+
"uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
|
|
47
|
+
},
|
|
48
|
+
arbitrum: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
|
|
49
|
+
hyperevm: {
|
|
50
|
+
prjx: strict("0x02E658B2B205F76850Cf6d584477A58cD797e46a"),
|
|
51
|
+
nest: strict("0x93aC608AA016271BBB92924C3838a0b550c34ce1"),
|
|
52
|
+
"ramses-ur": strict("0x4b22d4b3F104D76aB92A2CA4E5E4A08A27F18f52"),
|
|
53
|
+
hyperswap: strict("0x782DB7e687E16Bfe00C9a0CE41A76A7cC507566F"),
|
|
54
|
+
},
|
|
55
|
+
robinhood: {
|
|
56
|
+
"uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995"),
|
|
57
|
+
"ramses-ur": strict("0x4b22d4b3F104D76aB92A2CA4E5E4A08A27F18f52"),
|
|
58
|
+
},
|
|
59
|
+
arc: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
|
|
60
|
+
elysium: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const FLOOR_ROUTER_DEPLOYER = strict("0x3e70158e54E91d2984c0F3B66ce2cE730d1E0e11");
|
|
64
|
+
|
|
65
|
+
const ROUTER_PROXY_INITCODE = "0x67363d3d37363d34f03d5260086018f3";
|
|
66
|
+
|
|
67
|
+
function slotWord(slot ) {
|
|
68
|
+
const b = new TextEncoder().encode(slot);
|
|
69
|
+
if (b.length === 0 || b.length > 32) throw new RangeError(`a router slot is 1..32 bytes: ${JSON.stringify(slot)}`);
|
|
70
|
+
const w = new Uint8Array(32);
|
|
71
|
+
w.set(b);
|
|
72
|
+
return w;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function floorRouterAddress(slot , deployer = FLOOR_ROUTER_DEPLOYER) {
|
|
76
|
+
const s = keccak256(encodeAbi(["string", "bytes32"], ["floor-router.v1.FloorRouter", bytesToHex(slotWord(slot))]));
|
|
77
|
+
const proxy = create2Address({ deployer, salt: s, initCode: ROUTER_PROXY_INITCODE });
|
|
78
|
+
|
|
79
|
+
return checksumAddress(bytesToHex(keccak256(hexToBytes("0xd694" + proxy.slice(2) + "01")).slice(12)));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function withBookedZaps(key , rows ) {
|
|
83
|
+
const book = FLOOR_ZAP_ADDRESSES[key];
|
|
84
|
+
return rows.map((row) => ({ ...row, zap: book[row.slot] ?? null, floorRouter: floorRouterAddress(row.slot) }));
|
|
85
|
+
}
|
|
86
|
+
|
|
32
87
|
const UNISWAP_UR = "uniswap-ur";
|
|
33
88
|
|
|
34
89
|
const ROUTES = {
|
|
35
90
|
ethereum: {
|
|
36
91
|
wrappedNative: strict("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
|
37
|
-
zapRouters: [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x4C82D1fBFe28C977cBB58D8C7FF8FCF9F70a2cCA", "uniswap-ur", "HIGH")],
|
|
92
|
+
zapRouters: withBookedZaps("ethereum", [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x4C82D1fBFe28C977cBB58D8C7FF8FCF9F70a2cCA", "uniswap-ur", "HIGH")]),
|
|
38
93
|
notes: [],
|
|
39
94
|
},
|
|
40
95
|
base: {
|
|
41
96
|
wrappedNative: strict("0x4200000000000000000000000000000000000006"),
|
|
42
|
-
zapRouters: [
|
|
97
|
+
zapRouters: withBookedZaps("base", [
|
|
43
98
|
r("aerodrome-ur", "Aerodrome V1 + Slipstream", "0xC5b6786D7B64767D775877b0B6A319AD946B11B5", "uniswap-ur", "HIGH", false, true),
|
|
44
99
|
r(UNISWAP_UR, "Uniswap v2/v3/v4", "0xFdf682F51FE81Aa4898F0AE2163d8A55c127fbC7", "uniswap-ur", "HIGH"),
|
|
45
100
|
r("pancake-ur", "PancakeSwap V3 / Infinity", "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB", "uniswap-ur", "HIGH", true, true),
|
|
46
|
-
],
|
|
101
|
+
]),
|
|
47
102
|
notes: [],
|
|
48
103
|
},
|
|
49
104
|
bsc: {
|
|
50
105
|
wrappedNative: strict("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"),
|
|
51
|
-
zapRouters: [
|
|
106
|
+
zapRouters: withBookedZaps("bsc", [
|
|
52
107
|
r("pancake-ur", "PancakeSwap V2 / V3 / Infinity", "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB", "uniswap-ur", "HIGH", false, true),
|
|
53
108
|
r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH"),
|
|
54
|
-
],
|
|
109
|
+
]),
|
|
55
110
|
notes: ["⚠ 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD is Uniswap's UR v1.2, NOT PancakeSwap's: never use it as Pancake's."],
|
|
56
111
|
},
|
|
57
112
|
arbitrum: {
|
|
58
113
|
wrappedNative: strict("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"),
|
|
59
|
-
zapRouters: [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH")],
|
|
114
|
+
zapRouters: withBookedZaps("arbitrum", [r(UNISWAP_UR, "Uniswap v2/v3/v4", "0x8B844f885672f333Bc0042cB669255f93a4C1E6b", "uniswap-ur", "HIGH")]),
|
|
60
115
|
notes: [],
|
|
61
116
|
},
|
|
62
117
|
hyperevm: {
|
|
63
118
|
maxFloorHops: 2,
|
|
64
119
|
wrappedNative: strict("0x5555555555555555555555555555555555555555"),
|
|
65
|
-
zapRouters: [
|
|
120
|
+
zapRouters: withBookedZaps("hyperevm", [
|
|
66
121
|
r("prjx", "Project X", "0x1EbDFC75FfE3ba3de61E7138a3E8706aC841Af9B", "v3-router", "MEDIUM–HIGH"),
|
|
67
122
|
r("nest", "nest (CL)", "0xaA26B8e5Cadd04430c32787eCC3AA325e99681e9", "algebra", "HIGH"),
|
|
68
123
|
r("ramses-ur", "Ramses CL V2", "0xc43b33b5DF826A48DAE764817647824ED4f476a7", "uniswap-ur", "MEDIUM", false, true),
|
|
69
124
|
r("hyperswap", "HyperSwap V3", "0x6D99e7f6747AF2cDbB5164b6DD50e40D4fDe1e77", "v3-router02", "HIGH", true),
|
|
70
|
-
],
|
|
125
|
+
]),
|
|
71
126
|
notes: ["⚠ Small blocks cap a transaction at 3M gas: a buy that graduates a launch may need a big block."],
|
|
72
127
|
},
|
|
73
128
|
robinhood: {
|
|
74
129
|
wrappedNative: strict("0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73"),
|
|
75
|
-
zapRouters: [
|
|
130
|
+
zapRouters: withBookedZaps("robinhood", [
|
|
76
131
|
r(UNISWAP_UR, "Uniswap v2/v3/v4 (+ Fables v4 pools)", "0x8876789976dEcBfCbBbe364623C63652db8C0904", "uniswap-ur", "HIGH"),
|
|
77
132
|
r("ramses-ur", "Ramses", "0xbFbb2BCBc9dfFA029C27A249ae9BE031E1d83b1C", "uniswap-ur", "HIGH", true, true),
|
|
78
|
-
],
|
|
133
|
+
]),
|
|
79
134
|
notes: [],
|
|
80
135
|
},
|
|
81
136
|
arc: {
|
|
82
137
|
wrappedNative: null,
|
|
83
|
-
zapRouters: [r(UNISWAP_UR, "Uniswap v4 (native-USDC pools)", "0x4fcA4a51Ab4F23A7447b3284fBd7D73289A89Fb1", "uniswap-ur", "HIGH")],
|
|
138
|
+
zapRouters: withBookedZaps("arc", [r(UNISWAP_UR, "Uniswap v4 (native-USDC pools)", "0x4fcA4a51Ab4F23A7447b3284fBd7D73289A89Fb1", "uniswap-ur", "HIGH")]),
|
|
84
139
|
notes: [
|
|
85
140
|
"⚠ The native coin is USDC (18 dp at the EVM level; its ERC-20 view 0x3600000000000000000000000000000000000000 has 6 dp and no deposit()).",
|
|
86
141
|
"⚠ 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
142
|
],
|
|
88
143
|
},
|
|
144
|
+
elysium: {
|
|
145
|
+
|
|
146
|
+
wrappedNative: strict("0xbA876237B0F021A6c6D852d6c26E107997cC5E81"),
|
|
147
|
+
|
|
148
|
+
zapRouters: withBookedZaps("elysium", [r(UNISWAP_UR, "Uniswap v4 (native HYPE / USDC pools)", "0xA13f7611115752DEB2B13813BDDE16A5073e4b45", "uniswap-ur", "HIGH")]),
|
|
149
|
+
notes: [
|
|
150
|
+
"⚠ Arbitrum Orbit on HyperEVM: in a contract block.number is HyperEVM's block; the receipt's block is Elysium's.",
|
|
151
|
+
"⚠ 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.",
|
|
152
|
+
],
|
|
153
|
+
},
|
|
89
154
|
};
|
|
90
155
|
|
|
91
156
|
export const EVM_CHAINS = Object.fromEntries(
|
|
92
157
|
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
158
|
) ;
|
|
94
159
|
|
|
160
|
+
export const FLOOR_ROUTER_ADDRESSES = Object.freeze(
|
|
161
|
+
Object.fromEntries(Object.values(EVM_CHAINS).map((c) => [c.key, Object.freeze(Object.fromEntries(c.zapRouters.map((r) => [r.slot, r.floorRouter])))])),
|
|
162
|
+
) ;
|
|
163
|
+
|
|
95
164
|
export const v2DayOneChains = () => Object.values(EVM_CHAINS).filter((c) => c.v2DayOne !== false);
|
|
96
165
|
export const chainById = (chainId ) => Object.values(EVM_CHAINS).find((c) => c.chainId === chainId) ?? null;
|
|
97
166
|
|
|
@@ -110,7 +179,7 @@ export const FLOOR_SALTS = {
|
|
|
110
179
|
export const FLOOR_AMM_ADDRESS = "0xF10000bd05c2C01793C6d55F027346469683d225";
|
|
111
180
|
|
|
112
181
|
export const FLOOR_AMM_FROM_BLOCK = {
|
|
113
|
-
ethereum: 26327910, base: 53421827, bsc: 131270813, arbitrum: 520655168, arc: 29205598, robinhood: 104455459, hyperevm: 50398055,
|
|
182
|
+
ethereum: 26327910, base: 53421827, bsc: 131270813, arbitrum: 520655168, arc: 29205598, robinhood: 104455459, hyperevm: 50398055, elysium: 6058368,
|
|
114
183
|
};
|
|
115
184
|
|
|
116
185
|
const cat = (...h ) => "0x" + h.map((x) => bytesToHex(hexToBytes(x)).slice(2)).join("");
|
|
@@ -51,7 +51,7 @@ export const FLOOR_AMM_ABI = [
|
|
|
51
51
|
{"type":"error","name":"UnknownClaimType","inputs":[]},
|
|
52
52
|
{"type":"error","name":"UnknownLaunch","inputs":[]},
|
|
53
53
|
{"type":"event","name":"ClaimSkipped","inputs":[{"name":"wallet","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"amount","type":"uint256","indexed":false}],"anonymous":false},
|
|
54
|
-
{"type":"event","name":"Claimed","inputs":[{"name":"wallet","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"types","type":"
|
|
54
|
+
{"type":"event","name":"Claimed","inputs":[{"name":"wallet","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"types","type":"uint16","indexed":false},{"name":"creator","type":"uint256","indexed":false},{"name":"creatorRef","type":"uint256","indexed":false},{"name":"teamSlot","type":"uint256","indexed":false},{"name":"traderRef","type":"uint256","indexed":false},{"name":"holder","type":"uint256","indexed":false},{"name":"extra","type":"uint256","indexed":false},{"name":"amount","type":"uint256","indexed":false}],"anonymous":false},
|
|
55
55
|
{"type":"event","name":"ConfigWritten","inputs":[{"name":"authority","type":"address","indexed":false},{"name":"pendingAuthority","type":"address","indexed":false},{"name":"timelock","type":"address","indexed":false},{"name":"referralAuthority","type":"address","indexed":false},{"name":"createPaused","type":"bool","indexed":false},{"name":"holderDest","type":"address","indexed":false}],"anonymous":false},
|
|
56
56
|
{"type":"event","name":"CreatorBuyUnlocked","inputs":[{"name":"launchId","type":"uint256","indexed":true},{"name":"creator","type":"address","indexed":true},{"name":"tokens","type":"uint256","indexed":false},{"name":"members","type":"uint256[10]","indexed":false},{"name":"paid","type":"uint256","indexed":false}],"anonymous":false},
|
|
57
57
|
{"type":"event","name":"Graduated","inputs":[{"name":"launchId","type":"uint256","indexed":true},{"name":"windowPriceX64","type":"uint256","indexed":false},{"name":"priceX64","type":"uint256","indexed":false},{"name":"windowRaised","type":"uint256","indexed":false},{"name":"windowTokens","type":"uint256","indexed":false}],"anonymous":false},
|
package/dist/evm/floor/events.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { checksumAddress } from "../abi.js";
|
|
4
4
|
import { decodeEventLog, itemTopic } from "../items.js";
|
|
5
5
|
|
|
6
|
+
import { LEGACY_CLAIMED_TOPIC, LEGACY_EVENTS, normalizeLegacyClaimed } from "./legacy-events.js";
|
|
6
7
|
import { FLOOR_AMM_ABI, FLOOR_AMM_UNFROZEN_EVENTS, FLOOR_ZAP_ABI } from "./iface.js";
|
|
7
8
|
|
|
8
9
|
|
|
@@ -28,10 +29,17 @@ for (const i of ALL.filter((i) => i.type === "event").reverse()) {
|
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
export const FLOOR_LEGACY_EVENT_TOPICS = { Claimed: LEGACY_CLAIMED_TOPIC };
|
|
33
|
+
|
|
31
34
|
export function decodeFloorLog(log , from ) {
|
|
32
35
|
if (from && (!log.address || !from.some((a) => a.toLowerCase() === log.address .toLowerCase()))) return null;
|
|
33
36
|
const d = decodeEventLog(ALL, log);
|
|
34
|
-
if (!d)
|
|
37
|
+
if (!d) {
|
|
38
|
+
const old = decodeEventLog(LEGACY_EVENTS, log);
|
|
39
|
+
if (!old) return null;
|
|
40
|
+
const e = { ...old, args: normalizeLegacyClaimed(old.args), legacy: true };
|
|
41
|
+
return log.address ? { ...e, address: checksumAddress(log.address) } : e;
|
|
42
|
+
}
|
|
35
43
|
if (UNFROZEN().has((log.topics[0] ?? "").toLowerCase())) d.unfrozen = true;
|
|
36
44
|
return log.address ? { ...d, address: checksumAddress(log.address) } : d;
|
|
37
45
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export const LEGACY_CLAIMED_SIGNATURE =
|
|
4
|
+
"Claimed(address,address,address,uint8,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
|
|
5
|
+
export const LEGACY_CLAIMED_TOPIC = "0x586c69c7198e9e5c48c058d0267bd1388a73f9a8878aeb9d72d25331acc39aeb";
|
|
6
|
+
|
|
7
|
+
export const LEGACY_EVENTS = [
|
|
8
|
+
{
|
|
9
|
+
type: "event", name: "Claimed", anonymous: false, inputs: [
|
|
10
|
+
{ name: "wallet", type: "address", indexed: true }, { name: "sender", type: "address", indexed: true },
|
|
11
|
+
{ name: "quote", type: "address", indexed: true }, { name: "types", type: "uint8", indexed: false },
|
|
12
|
+
{ name: "creator", type: "uint256", indexed: false }, { name: "creatorRef", type: "uint256", indexed: false },
|
|
13
|
+
{ name: "teamSlot", type: "uint256", indexed: false }, { name: "traderRef", type: "uint256", indexed: false },
|
|
14
|
+
{ name: "holder", type: "uint256", indexed: false }, { name: "extra", type: "uint256", indexed: false },
|
|
15
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const CLAIM_HOLDER_BIT = 512n;
|
|
21
|
+
|
|
22
|
+
export function normalizeLegacyClaimed(args ) {
|
|
23
|
+
const types = BigInt(args.types);
|
|
24
|
+
return { ...args, types: BigInt(args.holder) > 0n ? types | CLAIM_HOLDER_BIT : types };
|
|
25
|
+
}
|
package/dist/evm/router.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { encodeFunctionData } from "./items.js";
|
|
4
4
|
import { deadlineArg } from "./floor/calls.js";
|
|
5
5
|
import { EVM_NATIVE, NoRouteError, coinKey } from "../route/graph.js";
|
|
6
|
-
import { chainById } from "./chains.js";
|
|
6
|
+
import { EVM_CHAINS, chainById } from "./chains.js";
|
|
7
7
|
|
|
8
8
|
const BUY = [
|
|
9
9
|
{ name: "path", type: "uint256[]" },
|
|
@@ -182,3 +182,27 @@ export function evmRouteCall(q , p
|
|
|
182
182
|
const b = { path: ids(buys), tokenIn: s.tokenOut, amountIn: 0n, swapData: "0x", minQuoteIn: 0n, minTokensOut: mins(buys), to: p.to, deadline: p.deadline };
|
|
183
183
|
return call(encodeRouterSwap(s, b, p.chainId), 0n);
|
|
184
184
|
}
|
|
185
|
+
|
|
186
|
+
export async function floorRouterLive(rpc , at ) {
|
|
187
|
+
const address = floorRouterAt(at);
|
|
188
|
+
const code = await rpc.getCode(address);
|
|
189
|
+
if (code === undefined) return false;
|
|
190
|
+
if (typeof code !== "string" || !/^0x([0-9a-fA-F]{2})*$/.test(code)) throw new TypeError(`getCode(${address}) returned ${String(code)}, not hex bytes`);
|
|
191
|
+
return code.length > 2;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export async function assertFloorRouterLive(rpc , at ) {
|
|
195
|
+
const address = floorRouterAt(at);
|
|
196
|
+
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)`);
|
|
197
|
+
return address;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function floorRouterAt(at ) {
|
|
201
|
+
if (typeof at === "string") {
|
|
202
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(at)) throw new RangeError(`a FloorRouter is a 20-byte address: ${at}`);
|
|
203
|
+
return at;
|
|
204
|
+
}
|
|
205
|
+
const row = EVM_CHAINS[at.chain]?.zapRouters.find((r) => r.slot === at.slot);
|
|
206
|
+
if (row === undefined) throw new RangeError(`no FloorRouter slot ${at.slot} on ${at.chain}`);
|
|
207
|
+
return row.floorRouter;
|
|
208
|
+
}
|
package/dist/evm/squid.js
CHANGED
|
@@ -65,19 +65,19 @@ export function buyHookErc20(p
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export function buyHookNative(p
|
|
68
|
+
export function buyHookNative(p ) {
|
|
69
69
|
checkCommon(p);
|
|
70
70
|
const user = checkUser(p);
|
|
71
71
|
if (p.minQuoteIn <= 0n || p.minTokensOut <= 0n) throw new SquidHookError("NO_MINIMUM", "minQuoteIn and minTokensOut must be > 0");
|
|
72
72
|
const zap = lc(p.zap, "zap");
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
73
|
+
const quote = lc(p.quote ?? ZERO, "quote");
|
|
74
|
+
const calls = [
|
|
75
|
+
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),
|
|
76
|
+
call(SQUID_CALL.FullNativeBalance, user, 0n, "0x", "0x", SQUID_GAS.passOn),
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
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));
|
|
80
|
+
return { provider: "FLOOR", description: "Buy a FLOOR launch token with the native coin", calls };
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export function sellHook(p ) {
|
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
|
}
|