-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathgenerate-table.js
More file actions
240 lines (228 loc) · 7.13 KB
/
generate-table.js
File metadata and controls
240 lines (228 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import * as fs from "fs";
import { markdownTable } from "markdown-table";
import stringWidth from "string-width";
/**
| UniswapV3 | DEX | Pair | Gas | % |
| -------------------- | ---------- | --------- | ------ | ------- |
| UniswapRouter V3 | Uniswap V3 | USDC/WETH | 127268 | 0.00% |
| Settler VIP (warm) | Uniswap V3 | USDC/WETH | 123126 | -3.25% |
| Settler VIP (cold) | Uniswap V3 | USDC/WETH | 152189 | 19.58% |
| Settler | Uniswap V3 | USDC/WETH | 163457 | 28.44% |
| 0x V4 VIP | Uniswap V3 | USDC/WETH | 131239 | 3.12% |
| 0x V4 Multiplex | Uniswap V3 | USDC/WETH | 144847 | 13.81% |
| 0x V4 TransformERC20 | Uniswap V3 | USDC/WETH | 250513 | 96.84% |
*/
// If you're reading this I am truly sorry
const readSnapshot = (name, pair) =>
fs.existsSync(`.forge-snapshots/${name}_${pair}.snap`)
? Number.parseInt(
fs
.readFileSync(`.forge-snapshots/${name}_${pair}.snap`)
.toString()
.replace(/\n/g, "")
)
: undefined;
const pairs = ["USDC-WETH", "DAI-WETH", "USDT-WETH", "WETH-USDC"];
const tables = [];
/**
* Reads in the snapshot from snapshot[2]_pair.snap, extracting the data and comparing it to the baseline snapshot.
* The first item in snapshots is used as the baseline to compare against.
*
* @param {*} name human readable name for the snapshot group, e.g MetaTransactions
* @param {*} snapshots array of [name, dex, filename]
* @param {*} pairs array of "-"" separated pairs which exist as snapshots
* @returns
*/
const generateTable = (name, snapshots, pairs) => {
const data = [[name, "DEX", "Pair", "Gas", "%"]];
for (const pair of pairs) {
const baselineData = readSnapshot(snapshots[0][2], pair);
for (const [snapshotName, snapshotDex, snapshotFilename] of snapshots) {
const snapshotData = readSnapshot(snapshotFilename, pair);
if (snapshotData === undefined) {
continue;
}
const baselineComparePerc =
(((snapshotData - baselineData) / baselineData) * 100).toFixed(2) + "%";
data.push([
snapshotName,
snapshotDex,
pair.split("-").join("/"),
snapshotData,
baselineComparePerc,
]);
}
data.push(["", "", "", ""]);
}
return data;
};
tables.push(
// UniswapV3 comparisons
markdownTable(
generateTable(
"VIP",
[
["0x V4 VIP", "Uniswap V3", "zeroEx_uniswapV3VIP"],
["0x V4 Multiplex", "Uniswap V3", "zeroEx_uniswapV3VIP_multiplex1"],
["Settler VIP (warm)", "Uniswap V3", "settler_uniswapV3VIP"],
["Settler VIP (cold)", "Uniswap V3", "settler_uniswapV3VIP_cold"],
["AllowanceHolder VIP", "Uniswap V3", "allowanceHolder_uniswapV3VIP"],
["UniswapRouter V3", "Uniswap V3", "uniswapRouter_uniswapV3"],
],
pairs
),
{ stringLength: stringWidth }
),
markdownTable(
generateTable(
"Custody",
[
[
"0x V4 TransformERC20",
"Uniswap V3",
"zeroEx_uniswapV3_transformERC20",
],
["Settler", "Uniswap V3", "settler_uniswapV3"],
["AllowanceHolder", "Uniswap V3", "allowanceHolder_uniswapV3"],
],
pairs
),
{ stringLength: stringWidth }
),
// MetaTransaction comparisons
markdownTable(
generateTable(
"MetaTransactions",
[
["0x V4 Multiplex", "Uniswap V3", "zeroEx_metaTxn_uniswapV3"],
["Settler", "Uniswap V3", "settler_metaTxn_uniswapV3"],
],
pairs
),
{ stringLength: stringWidth }
),
// RFQ comparisons
markdownTable(
generateTable(
"RFQ",
[
["0x V4", "0x V4", "zeroEx_otcOrder"],
["Settler", "Settler", "settler_rfq"],
["Settler", "0x V4", "settler_zeroExOtc"],
["AllowanceHolder", "Settler", "allowanceHolder_rfq"],
],
pairs
),
{ stringLength: stringWidth }
),
// Uniswap UniversalRouter comparisons
markdownTable(
generateTable(
"UniversalRouter",
[
["UniversalRouter", "UniswapV2", "universalRouter_uniswapV2"],
["Settler", "UniswapV2", "settler_uniswapV2_toNative"],
["Settler", "UniswapV2", "settler_uniswapV2_fromNative"],
["UniversalRouter", "UniswapV3", "universalRouter_uniswapV3"],
["Settler", "UniswapV3", "settler_uniswapV3VIP_toNative"],
["Settler", "UniswapV3", "settler_uniswapV3_fromNative"],
["UniversalRouter", "UniswapV4", "universalRouter_uniswapV4"],
["Settler", "UniswapV4", "settler_uniswapV4VIP_toNative"],
["Settler", "UniswapV4", "settler_uniswapV4_fromNative"],
],
pairs
),
{ stringLength: stringWidth }
),
// Curve comparisons
markdownTable(
generateTable(
"Curve",
[
["0x V4", "Curve", "zeroEx_curveV2VIP"],
["Settler", "Curve", "settler_basic_curve"],
["Settler", "CurveV2 Tricrypto VIP", "settler_curveTricrypto"],
["Curve", "Curve", "curveV2Pool"],
["Curve Swap Router", "Curve", "curveV2Pool_swapRouter"],
],
pairs
),
{ stringLength: stringWidth }
),
// Dodo
markdownTable(
generateTable(
"DODO V1",
[
["Settler", "DODO V1", "settler_dodoV1"],
],
pairs
),
{ stringLength: stringWidth }
),
// Swap with buy token fees comparisons
markdownTable(
generateTable(
"Buy token fee",
[
[
"Settler - custody",
"Uniswap V3",
"settler_uniswapV3_buyToken_fee_single_custody",
],
["Settler", "RFQ", "settler_rfq_buyToken_fee"],
],
pairs
),
{ stringLength: stringWidth }
),
// Swap with sell token fees comparisons
markdownTable(
generateTable(
"Sell token fee",
[
["Settler", "Uniswap V3", "settler_uniswapV3_sellToken_fee_full_custody"],
["Settler", "RFQ", "settler_rfq_sellToken_fee"],
["Settler", "Curve", "settler_curveV2_fee"],
],
pairs
),
{ stringLength: stringWidth }
),
// Allowance Holder
markdownTable(
generateTable(
"AllowanceHolder",
[
["execute", "Uniswap V3 VIP", "allowanceHolder_uniswapV3VIP"],
["Settler - external move then execute", "Uniswap V3", "settler_externalMoveExecute_uniswapV3"],
["execute", "RFQ", "allowanceHolder_rfq"],
],
pairs
),
{ stringLength: stringWidth }
),
// Allowance Holder RFQ fees
markdownTable(
generateTable(
"AllowanceHolder sell token fees",
[
["no fee", "RFQ", "allowanceHolder_rfq"],
["proportional fee", "RFQ", "allowanceHolder_rfq_proportionalFee_sellToken"],
["fixed fee", "RFQ", "allowanceHolder_rfq_fixedFee_sellToken"],
],
pairs
),
{ stringLength: stringWidth }
)
);
const inputFile = "README.md";
const beginToken = `[//]: # "BEGIN TABLES"`;
const endToken = `[//]: # "END TABLES"`;
const contents = fs.readFileSync(inputFile, "utf8");
const tableData = tables.map((t) => t.toString()).join("\n\n");
const modifiedData = contents.replace(
new RegExp(`\\${beginToken}[\\s\\S]*?\\${endToken}`, "g"),
`${beginToken}\n\n${tableData}\n\n${endToken}`
);
fs.writeFileSync(inputFile, modifiedData);