@paraswap/dex-lib 4.8.33 → 4.8.34-pancake-infinity.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/build/abi/pancakeswap-infinity/cl-pool-manager.json +80 -0
- package/build/dex/fluid-dex/scripts/measure-calc-time.d.ts +1 -0
- package/build/dex/fluid-dex/scripts/measure-calc-time.js +178 -0
- package/build/dex/fluid-dex/scripts/measure-calc-time.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-infinity/config.d.ts +3 -0
- package/build/dex/pancakeswap-infinity/config.js +14 -0
- package/build/dex/pancakeswap-infinity/config.js.map +1 -0
- package/build/dex/pancakeswap-infinity/encoder.d.ts +4 -0
- package/build/dex/pancakeswap-infinity/encoder.js +205 -0
- package/build/dex/pancakeswap-infinity/encoder.js.map +1 -0
- package/build/dex/pancakeswap-infinity/pancakeswap-infinity.d.ts +21 -0
- package/build/dex/pancakeswap-infinity/pancakeswap-infinity.js +102 -0
- package/build/dex/pancakeswap-infinity/pancakeswap-infinity.js.map +1 -0
- package/build/dex/pancakeswap-infinity/subgraph.d.ts +7 -0
- package/build/dex/pancakeswap-infinity/subgraph.js +64 -0
- package/build/dex/pancakeswap-infinity/subgraph.js.map +1 -0
- package/build/dex/pancakeswap-infinity/types.d.ts +31 -0
- package/build/dex/pancakeswap-infinity/types.js +3 -0
- package/build/dex/pancakeswap-infinity/types.js.map +1 -0
- package/build/dex/pancakeswap-v3/scripts/measure-calc-time.d.ts +1 -0
- package/build/dex/pancakeswap-v3/scripts/measure-calc-time.js +203 -0
- package/build/dex/pancakeswap-v3/scripts/measure-calc-time.js.map +1 -0
- package/build/dex/solidly-v3/contract-math/native-bridge.d.ts +26 -0
- package/build/dex/solidly-v3/contract-math/native-bridge.js +96 -0
- package/build/dex/solidly-v3/contract-math/native-bridge.js.map +1 -0
- package/build/dex/solidly-v3/scripts/measure-calc-time.d.ts +1 -0
- package/build/dex/solidly-v3/scripts/measure-calc-time.js +203 -0
- package/build/dex/solidly-v3/scripts/measure-calc-time.js.map +1 -0
- package/build/dex/uniswap-v3/contract-math/native-bridge.d.ts +52 -1
- package/build/dex/uniswap-v3/contract-math/native-bridge.js +27 -3
- package/build/dex/uniswap-v3/contract-math/native-bridge.js.map +1 -1
- package/build/dex/uniswap-v3/scripts/bench-e2e.d.ts +1 -0
- package/build/dex/uniswap-v3/scripts/bench-e2e.js +85 -0
- package/build/dex/uniswap-v3/scripts/bench-e2e.js.map +1 -0
- package/build/dex/uniswap-v3/scripts/bench-parallel.d.ts +1 -0
- package/build/dex/uniswap-v3/scripts/bench-parallel.js +192 -0
- package/build/dex/uniswap-v3/scripts/bench-parallel.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/native-bridge.d.ts +40 -0
- package/build/dex/uniswap-v4/contract-math/native-bridge.js +74 -0
- package/build/dex/uniswap-v4/contract-math/native-bridge.js.map +1 -0
- package/build/dex/uniswap-v4/scripts/test-rust-correctness.d.ts +1 -0
- package/build/dex/uniswap-v4/scripts/test-rust-correctness.js +167 -0
- package/build/dex/uniswap-v4/scripts/test-rust-correctness.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
+
import { Pool, PoolState } from '../types';
|
|
3
|
+
export declare const nativeAddonAvailable: boolean;
|
|
4
|
+
export type V4RegistryQueryResult = {
|
|
5
|
+
key: string;
|
|
6
|
+
outputs: bigint[];
|
|
7
|
+
};
|
|
8
|
+
export type RustV4RegistryType = {
|
|
9
|
+
setPool(key: string, init: ReturnType<typeof toV4RustInit>): void;
|
|
10
|
+
removePool(key: string): void;
|
|
11
|
+
queryMany(keys: string[], amounts: bigint[], zeroForOne: boolean, side: number): V4RegistryQueryResult[];
|
|
12
|
+
poolCount(): number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Convert a V4 PoolState + Pool to the init format expected by
|
|
16
|
+
* the Rust RustV4PoolRegistry addon.
|
|
17
|
+
*/
|
|
18
|
+
export declare function toV4RustInit(state: DeepReadonly<PoolState>, pool: DeepReadonly<Pool>, networkId?: number): {
|
|
19
|
+
sqrtPriceX96: bigint;
|
|
20
|
+
tick: bigint;
|
|
21
|
+
protocolFee: bigint;
|
|
22
|
+
lpFee: bigint;
|
|
23
|
+
liquidity: bigint;
|
|
24
|
+
tickSpacing: bigint;
|
|
25
|
+
feeGrowthGlobal0X128: bigint;
|
|
26
|
+
feeGrowthGlobal1X128: bigint;
|
|
27
|
+
bitmapRange: number;
|
|
28
|
+
startTickBitmap: bigint;
|
|
29
|
+
tickBitmap: {
|
|
30
|
+
key: number;
|
|
31
|
+
value: bigint;
|
|
32
|
+
}[];
|
|
33
|
+
ticks: {
|
|
34
|
+
key: number;
|
|
35
|
+
liquidityGross: bigint;
|
|
36
|
+
liquidityNet: bigint;
|
|
37
|
+
}[];
|
|
38
|
+
};
|
|
39
|
+
export declare function createV4Registry(): RustV4RegistryType | null;
|
|
40
|
+
export declare function v4RegistrySetPool(registry: RustV4RegistryType, key: string, state: DeepReadonly<PoolState>, pool: DeepReadonly<Pool>, networkId?: number): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nativeAddonAvailable = void 0;
|
|
4
|
+
exports.toV4RustInit = toV4RustInit;
|
|
5
|
+
exports.createV4Registry = createV4Registry;
|
|
6
|
+
exports.v4RegistrySetPool = v4RegistrySetPool;
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const TickBitMap_1 = require("./TickBitMap");
|
|
9
|
+
// Try to load the native Rust addon
|
|
10
|
+
let nativeAddon = null;
|
|
11
|
+
try {
|
|
12
|
+
nativeAddon = require('../../../../native/index.js');
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// Native addon not available — JS fallback will be used
|
|
16
|
+
}
|
|
17
|
+
exports.nativeAddonAvailable = nativeAddon !== null;
|
|
18
|
+
/**
|
|
19
|
+
* Convert a V4 PoolState + Pool to the init format expected by
|
|
20
|
+
* the Rust RustV4PoolRegistry addon.
|
|
21
|
+
*/
|
|
22
|
+
function toV4RustInit(state, pool, networkId) {
|
|
23
|
+
const tickBitmap = Object.entries(state.tickBitmap).map(([key, value]) => ({
|
|
24
|
+
key: Number(key),
|
|
25
|
+
value,
|
|
26
|
+
}));
|
|
27
|
+
const ticks = Object.entries(state.ticks).map(([key, info]) => ({
|
|
28
|
+
key: Number(key),
|
|
29
|
+
liquidityGross: info.liquidityGross,
|
|
30
|
+
liquidityNet: info.liquidityNet,
|
|
31
|
+
}));
|
|
32
|
+
const tickSpacing = BigInt(pool.key.tickSpacing);
|
|
33
|
+
const compressed = TickBitMap_1.TickBitMap.compress(state.slot0.tick, tickSpacing);
|
|
34
|
+
const startTickBitmap = TickBitMap_1.TickBitMap.position(compressed)[0];
|
|
35
|
+
const bitmapUse = Number(networkId !== undefined
|
|
36
|
+
? constants_1.TICK_BITMAP_TO_USE_BY_CHAIN[networkId] ?? constants_1.TICK_BITMAP_TO_USE
|
|
37
|
+
: constants_1.TICK_BITMAP_TO_USE);
|
|
38
|
+
const bitmapBuffer = Number(networkId !== undefined
|
|
39
|
+
? constants_1.TICK_BITMAP_BUFFER_BY_CHAIN[networkId] ?? constants_1.TICK_BITMAP_BUFFER
|
|
40
|
+
: constants_1.TICK_BITMAP_BUFFER);
|
|
41
|
+
return {
|
|
42
|
+
sqrtPriceX96: state.slot0.sqrtPriceX96,
|
|
43
|
+
tick: state.slot0.tick,
|
|
44
|
+
protocolFee: BigInt(state.slot0.protocolFee),
|
|
45
|
+
lpFee: BigInt(state.slot0.lpFee),
|
|
46
|
+
liquidity: state.liquidity,
|
|
47
|
+
tickSpacing,
|
|
48
|
+
feeGrowthGlobal0X128: state.feeGrowthGlobal0X128,
|
|
49
|
+
feeGrowthGlobal1X128: state.feeGrowthGlobal1X128,
|
|
50
|
+
bitmapRange: bitmapBuffer + bitmapUse,
|
|
51
|
+
startTickBitmap,
|
|
52
|
+
tickBitmap,
|
|
53
|
+
ticks,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function createV4Registry() {
|
|
57
|
+
if (!exports.nativeAddonAvailable)
|
|
58
|
+
return null;
|
|
59
|
+
try {
|
|
60
|
+
return new nativeAddon.RustV4PoolRegistry();
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function v4RegistrySetPool(registry, key, state, pool, networkId) {
|
|
67
|
+
try {
|
|
68
|
+
registry.setPool(key, toV4RustInit(state, pool, networkId));
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// silently skip — pool will use JS fallback
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=native-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-bridge.js","sourceRoot":"","sources":["../../../../src/dex/uniswap-v4/contract-math/native-bridge.ts"],"names":[],"mappings":";;;AA0CA,oCAoDC;AAED,4CAOC;AAED,8CAYC;AAlHD,4CAKsB;AACtB,6CAA0C;AAE1C,oCAAoC;AACpC,IAAI,WAAW,GAAQ,IAAI,CAAC;AAC5B,IAAI,CAAC;IACH,WAAW,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACvD,CAAC;AAAC,MAAM,CAAC;IACP,wDAAwD;AAC1D,CAAC;AAEY,QAAA,oBAAoB,GAAG,WAAW,KAAK,IAAI,CAAC;AAmBzD;;;GAGG;AACH,SAAgB,YAAY,CAC1B,KAA8B,EAC9B,IAAwB,EACxB,SAAkB;IAElB,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAC/B,KAAK,CAAC,UAA4C,CACnD,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,C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WAAW;QACX,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,WAAW,EAAE,YAAY,GAAG,SAAS;QACrC,eAAe;QACf,UAAU;QACV,KAAK;KACN,CAAC;AACJ,CAAC;AAED,SAAgB,gBAAgB;IAC9B,IAAI,CAAC,4BAAoB;QAAE,OAAO,IAAI,CAAC;IACvC,IAAI,CAAC;QACH,OAAO,IAAI,WAAW,CAAC,kBAAkB,EAAE,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAgB,iBAAiB,CAC/B,QAA4B,EAC5B,GAAW,EACX,KAA8B,EAC9B,IAAwB,EACxB,SAAkB;IAElB,IAAI,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,4CAA4C;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
/* eslint-disable no-console */
|
|
37
|
+
/*
|
|
38
|
+
* V4 Rust correctness test: compares JS vs Rust queryOutputs on real pool states.
|
|
39
|
+
* Directly instantiates pools and generates state, bypassing getPricesVolume.
|
|
40
|
+
*/
|
|
41
|
+
const dotenv = __importStar(require("dotenv"));
|
|
42
|
+
dotenv.config();
|
|
43
|
+
const constants_1 = require("../../../constants");
|
|
44
|
+
const dex_helper_1 = require("../../../dex-helper");
|
|
45
|
+
const uniswap_v4_1 = require("../uniswap-v4");
|
|
46
|
+
const uniswap_v4_pool_math_1 = require("../contract-math/uniswap-v4-pool-math");
|
|
47
|
+
const native_bridge_1 = require("../contract-math/native-bridge");
|
|
48
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
49
|
+
const utils_1 = require("../../../utils");
|
|
50
|
+
const RUNS = 1000;
|
|
51
|
+
(async () => {
|
|
52
|
+
const dh = new dex_helper_1.DummyDexHelper(constants_1.Network.MAINNET);
|
|
53
|
+
const bn = await dh.web3Provider.eth.getBlockNumber();
|
|
54
|
+
const dex = new uniswap_v4_1.UniswapV4(constants_1.Network.MAINNET, 'UniswapV4', dh);
|
|
55
|
+
const USDC = {
|
|
56
|
+
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
57
|
+
decimals: 6,
|
|
58
|
+
};
|
|
59
|
+
const WETH = {
|
|
60
|
+
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
61
|
+
decimals: 18,
|
|
62
|
+
};
|
|
63
|
+
console.log(`Block: ${bn}\n`);
|
|
64
|
+
// Initialize and discover pools
|
|
65
|
+
await dex.initializePricing(bn);
|
|
66
|
+
const ids = await dex.getPoolIdentifiers(USDC, WETH, constants_1.SwapSide.SELL, bn);
|
|
67
|
+
console.log(`Pool identifiers: ${ids.length}`);
|
|
68
|
+
ids.forEach(id => console.log(` ${id}`));
|
|
69
|
+
// Wait for async state generation
|
|
70
|
+
console.log('\nWaiting for pool state generation...');
|
|
71
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
72
|
+
// Access pool manager internals to get pool states directly
|
|
73
|
+
const poolManager = dex.poolManager;
|
|
74
|
+
const amounts = [
|
|
75
|
+
0n,
|
|
76
|
+
...Array.from({ length: 20 }, (_, i) => (0, utils_1.getBigIntPow)(6) * BigInt((i + 1) * 500)),
|
|
77
|
+
];
|
|
78
|
+
const registry = (0, native_bridge_1.createV4Registry)();
|
|
79
|
+
if (!registry) {
|
|
80
|
+
console.log('Rust addon not available');
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
let testedPools = 0;
|
|
84
|
+
for (const poolId of ids) {
|
|
85
|
+
const eventPool = await poolManager.getEventPool(poolId, bn);
|
|
86
|
+
if (!eventPool) {
|
|
87
|
+
console.log(`\n${poolId.slice(0, 16)}... no event pool`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const state = eventPool.getState(bn);
|
|
91
|
+
if (!state) {
|
|
92
|
+
console.log(`\n${poolId.slice(0, 16)}... no state`);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// Find the Pool object for this id
|
|
96
|
+
const pools = await poolManager.getAvailablePoolsForPair(USDC.address.toLowerCase(), WETH.address.toLowerCase(), bn);
|
|
97
|
+
const pool = pools.find((p) => p.id === poolId);
|
|
98
|
+
if (!pool) {
|
|
99
|
+
console.log(`\n${poolId.slice(0, 16)}... pool object not found`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const tickSpacing = pool.key.tickSpacing;
|
|
103
|
+
const fromAddress = USDC.address.toLowerCase();
|
|
104
|
+
const currency0 = pool.key.currency0;
|
|
105
|
+
const zeroForOne = fromAddress === currency0 ||
|
|
106
|
+
(fromAddress === WETH.address.toLowerCase() &&
|
|
107
|
+
currency0 === '0x0000000000000000000000000000000000000000');
|
|
108
|
+
console.log(`\n${poolId.slice(0, 16)}... tickSpacing=${tickSpacing} ticks=${Object.keys(state.ticks).length} liquidity=${state.liquidity}`);
|
|
109
|
+
console.log(` sqrtPrice=${state.slot0.sqrtPriceX96} tick=${state.slot0.tick} zeroForOne=${zeroForOne}`);
|
|
110
|
+
console.log(` protocolFee=${state.slot0.protocolFee} lpFee=${state.slot0.lpFee}`);
|
|
111
|
+
// Check if pool has hooks
|
|
112
|
+
const hasHooks = pool.key.hooks !== '0x0000000000000000000000000000000000000000';
|
|
113
|
+
if (hasHooks) {
|
|
114
|
+
console.log(` HOOKS: ${pool.key.hooks} — skipping Rust (hooks need JS)`);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// JS queryOutputs
|
|
118
|
+
const jsOutputs = uniswap_v4_pool_math_1.uniswapV4PoolMath.queryOutputs(pool, state, amounts, zeroForOne, constants_1.SwapSide.SELL);
|
|
119
|
+
// Rust queryOutputs via registry
|
|
120
|
+
(0, native_bridge_1.v4RegistrySetPool)(registry, poolId, state, pool);
|
|
121
|
+
const rustResults = registry.queryMany([poolId], amounts, zeroForOne, 0);
|
|
122
|
+
const rustOutputs = rustResults.find((r) => r.key === poolId)?.outputs;
|
|
123
|
+
if (!rustOutputs) {
|
|
124
|
+
console.log(' Rust: no results returned');
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
// Compare
|
|
128
|
+
let mismatches = 0;
|
|
129
|
+
for (let i = 0; i < amounts.length; i++) {
|
|
130
|
+
if (jsOutputs[i] !== rustOutputs[i]) {
|
|
131
|
+
mismatches++;
|
|
132
|
+
if (mismatches <= 5) {
|
|
133
|
+
console.log(` MISMATCH[${i}] amount=${amounts[i]} js=${jsOutputs[i]} rust=${rustOutputs[i]}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (mismatches === 0) {
|
|
138
|
+
console.log(` CORRECT: all ${amounts.length} outputs match`);
|
|
139
|
+
// Benchmark
|
|
140
|
+
const jsM = [];
|
|
141
|
+
for (let i = 0; i < RUNS; i++) {
|
|
142
|
+
const s = perf_hooks_1.performance.now();
|
|
143
|
+
uniswap_v4_pool_math_1.uniswapV4PoolMath.queryOutputs(pool, state, amounts, zeroForOne, constants_1.SwapSide.SELL);
|
|
144
|
+
jsM.push(perf_hooks_1.performance.now() - s);
|
|
145
|
+
}
|
|
146
|
+
const rustM = [];
|
|
147
|
+
for (let i = 0; i < RUNS; i++) {
|
|
148
|
+
const s = perf_hooks_1.performance.now();
|
|
149
|
+
registry.queryMany([poolId], amounts, zeroForOne, 0);
|
|
150
|
+
rustM.push(perf_hooks_1.performance.now() - s);
|
|
151
|
+
}
|
|
152
|
+
const jsP50 = [...jsM]
|
|
153
|
+
.sort((a, b) => a - b)[Math.floor(jsM.length * 0.5)].toFixed(3);
|
|
154
|
+
const rustP50 = [...rustM]
|
|
155
|
+
.sort((a, b) => a - b)[Math.floor(rustM.length * 0.5)].toFixed(3);
|
|
156
|
+
const speedup = (parseFloat(jsP50) / parseFloat(rustP50)).toFixed(1);
|
|
157
|
+
console.log(` JS p50=${jsP50}ms Rust p50=${rustP50}ms speedup=${speedup}x`);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
console.log(` ${mismatches}/${amounts.length} MISMATCHES`);
|
|
161
|
+
}
|
|
162
|
+
testedPools++;
|
|
163
|
+
}
|
|
164
|
+
console.log(`\nTested ${testedPools} pools`);
|
|
165
|
+
process.exit(0);
|
|
166
|
+
})();
|
|
167
|
+
//# sourceMappingURL=test-rust-correctness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-rust-correctness.js","sourceRoot":"","sources":["../../../../src/dex/uniswap-v4/scripts/test-rust-correctness.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAA+B;AAC/B;;;GAGG;AACH,+CAAiC;AACjC,MAAM,CAAC,MAAM,EAAE,CAAC;AAChB,kDAAuD;AACvD,oDAAqD;AACrD,8CAA0C;AAC1C,gFAA0E;AAC1E,kEAGwC;AACxC,2CAAyC;AACzC,0CAA8C;AAG9C,MAAM,IAAI,GAAG,IAAI,CAAC;AAElB,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,EAAE,GAAG,IAAI,2BAAc,CAAC,mBAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;IACtD,MAAM,GAAG,GAAG,IAAI,sBAAS,CAAC,mBAAO,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;IAE5D,MAAM,IAAI,GAAG;QACX,OAAO,EAAE,4CAA4C;QACrD,QAAQ,EAAE,CAAC;KACZ,CAAC;IACF,MAAM,IAAI,GAAG;QACX,OAAO,EAAE,4CAA4C;QACrD,QAAQ,EAAE,EAAE;KACb,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAE9B,gCAAgC;IAChC,MAA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