@paraswap/dex-lib 4.8.34-uni-v3-rust.1 → 4.8.34

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.
Files changed (82) hide show
  1. package/build/dex/idex.d.ts +1 -1
  2. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.d.ts +0 -2
  3. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +0 -5
  4. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -1
  5. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -6
  6. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +9 -85
  7. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  8. package/build/dex/solidly-v3/solidly-v3-pool.d.ts +0 -3
  9. package/build/dex/solidly-v3/solidly-v3-pool.js +0 -8
  10. package/build/dex/solidly-v3/solidly-v3-pool.js.map +1 -1
  11. package/build/dex/solidly-v3/solidly-v3.d.ts +2 -5
  12. package/build/dex/solidly-v3/solidly-v3.js +8 -84
  13. package/build/dex/solidly-v3/solidly-v3.js.map +1 -1
  14. package/build/dex/uniswap-v3/contract-math/native-bridge.d.ts +1 -52
  15. package/build/dex/uniswap-v3/contract-math/native-bridge.js +3 -27
  16. package/build/dex/uniswap-v3/contract-math/native-bridge.js.map +1 -1
  17. package/build/dex/uniswap-v3/scripts/measure-calc-time.js +110 -222
  18. package/build/dex/uniswap-v3/scripts/measure-calc-time.js.map +1 -1
  19. package/build/dex/uniswap-v3/types.d.ts +0 -1
  20. package/build/dex/uniswap-v3/types.js.map +1 -1
  21. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +0 -2
  22. package/build/dex/uniswap-v3/uniswap-v3-pool.js +0 -5
  23. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  24. package/build/dex/uniswap-v3/uniswap-v3.d.ts +3 -11
  25. package/build/dex/uniswap-v3/uniswap-v3.js +9 -86
  26. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  27. package/build/dex/uniswap-v4/types.d.ts +0 -1
  28. package/build/dex/uniswap-v4/uniswap-v4-pool-manager.d.ts +0 -2
  29. package/build/dex/uniswap-v4/uniswap-v4-pool-manager.js +0 -3
  30. package/build/dex/uniswap-v4/uniswap-v4-pool-manager.js.map +1 -1
  31. package/build/dex/uniswap-v4/uniswap-v4-pool.d.ts +0 -3
  32. package/build/dex/uniswap-v4/uniswap-v4-pool.js +0 -18
  33. package/build/dex/uniswap-v4/uniswap-v4-pool.js.map +1 -1
  34. package/build/dex/uniswap-v4/uniswap-v4.d.ts +1 -3
  35. package/build/dex/uniswap-v4/uniswap-v4.js +14 -74
  36. package/build/dex/uniswap-v4/uniswap-v4.js.map +1 -1
  37. package/build/pricing-helper.d.ts +1 -1
  38. package/build/pricing-helper.js +2 -2
  39. package/build/pricing-helper.js.map +1 -1
  40. package/package.json +1 -2
  41. package/build/dex/pancakeswap-v3/scripts/measure-calc-time.d.ts +0 -1
  42. package/build/dex/pancakeswap-v3/scripts/measure-calc-time.js +0 -203
  43. package/build/dex/pancakeswap-v3/scripts/measure-calc-time.js.map +0 -1
  44. package/build/dex/solidly-v3/contract-math/native-bridge.d.ts +0 -26
  45. package/build/dex/solidly-v3/contract-math/native-bridge.js +0 -96
  46. package/build/dex/solidly-v3/contract-math/native-bridge.js.map +0 -1
  47. package/build/dex/solidly-v3/scripts/measure-calc-time.d.ts +0 -1
  48. package/build/dex/solidly-v3/scripts/measure-calc-time.js +0 -203
  49. package/build/dex/solidly-v3/scripts/measure-calc-time.js.map +0 -1
  50. package/build/dex/uniswap-v3/scripts/bench-e2e.d.ts +0 -1
  51. package/build/dex/uniswap-v3/scripts/bench-e2e.js +0 -85
  52. package/build/dex/uniswap-v3/scripts/bench-e2e.js.map +0 -1
  53. package/build/dex/uniswap-v3/scripts/bench-parallel.d.ts +0 -1
  54. package/build/dex/uniswap-v3/scripts/bench-parallel.js +0 -192
  55. package/build/dex/uniswap-v3/scripts/bench-parallel.js.map +0 -1
  56. package/build/dex/uniswap-v4/contract-math/native-bridge.d.ts +0 -40
  57. package/build/dex/uniswap-v4/contract-math/native-bridge.js +0 -74
  58. package/build/dex/uniswap-v4/contract-math/native-bridge.js.map +0 -1
  59. package/build/dex/uniswap-v4/scripts/test-rust-correctness.d.ts +0 -1
  60. package/build/dex/uniswap-v4/scripts/test-rust-correctness.js +0 -167
  61. package/build/dex/uniswap-v4/scripts/test-rust-correctness.js.map +0 -1
  62. package/native/Cargo.lock +0 -331
  63. package/native/Cargo.toml +0 -22
  64. package/native/build.rs +0 -5
  65. package/native/package-lock.json +0 -32
  66. package/native/package.json +0 -20
  67. package/native/src/config.rs +0 -73
  68. package/native/src/lib.rs +0 -528
  69. package/native/src/math/bit_math.rs +0 -177
  70. package/native/src/math/full_math.rs +0 -217
  71. package/native/src/math/liquidity_math.rs +0 -72
  72. package/native/src/math/mod.rs +0 -10
  73. package/native/src/math/oracle.rs +0 -493
  74. package/native/src/math/sqrt_price_math.rs +0 -272
  75. package/native/src/math/swap_math.rs +0 -306
  76. package/native/src/math/tick.rs +0 -239
  77. package/native/src/math/tick_bitmap.rs +0 -312
  78. package/native/src/math/tick_math.rs +0 -321
  79. package/native/src/math/unsafe_math.rs +0 -67
  80. package/native/src/pool_state.rs +0 -41
  81. package/native/src/query_outputs.rs +0 -379
  82. package/native/src/v4_query_outputs.rs +0 -255
@@ -1,167 +0,0 @@
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
@@ -1 +0,0 @@
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,MAAM,GAAG,CAAC,iBAAiB,CAAC,EAAE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ACrD,KAAK,CAAC,IAAI,CAAC,wBAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YACpC,CAAC;YAED,MAAM,KAAK,GAAG,CAAC,GAAG,GAAG,CAAC;iBACnB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CACrB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,MAAM,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC;iBACvB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CACrB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC9C,MAAM,OAAO,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAErE,OAAO,CAAC,GAAG,CACT,YAAY,KAAK,gBAAgB,OAAO,eAAe,OAAO,GAAG,CAClE,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,KAAK,UAAU,IAAI,OAAO,CAAC,MAAM,aAAa,CAAC,CAAC;QAC9D,CAAC;QAED,WAAW,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,YAAY,WAAW,QAAQ,CAAC,CAAC;IAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,EAAE,CAAC"}
package/native/Cargo.lock DELETED
@@ -1,331 +0,0 @@
1
- # This file is automatically @generated by Cargo.
2
- # It is not intended for manual editing.
3
- version = 4
4
-
5
- [[package]]
6
- name = "aho-corasick"
7
- version = "1.1.4"
8
- source = "registry+https://github.com/rust-lang/crates.io-index"
9
- checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
10
- dependencies = [
11
- "memchr",
12
- ]
13
-
14
- [[package]]
15
- name = "bitflags"
16
- version = "2.11.0"
17
- source = "registry+https://github.com/rust-lang/crates.io-index"
18
- checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
19
-
20
- [[package]]
21
- name = "cfg-if"
22
- version = "1.0.4"
23
- source = "registry+https://github.com/rust-lang/crates.io-index"
24
- checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
25
-
26
- [[package]]
27
- name = "convert_case"
28
- version = "0.6.0"
29
- source = "registry+https://github.com/rust-lang/crates.io-index"
30
- checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
31
- dependencies = [
32
- "unicode-segmentation",
33
- ]
34
-
35
- [[package]]
36
- name = "crossbeam-deque"
37
- version = "0.8.6"
38
- source = "registry+https://github.com/rust-lang/crates.io-index"
39
- checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
40
- dependencies = [
41
- "crossbeam-epoch",
42
- "crossbeam-utils",
43
- ]
44
-
45
- [[package]]
46
- name = "crossbeam-epoch"
47
- version = "0.9.18"
48
- source = "registry+https://github.com/rust-lang/crates.io-index"
49
- checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
50
- dependencies = [
51
- "crossbeam-utils",
52
- ]
53
-
54
- [[package]]
55
- name = "crossbeam-utils"
56
- version = "0.8.21"
57
- source = "registry+https://github.com/rust-lang/crates.io-index"
58
- checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
59
-
60
- [[package]]
61
- name = "ctor"
62
- version = "0.2.9"
63
- source = "registry+https://github.com/rust-lang/crates.io-index"
64
- checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501"
65
- dependencies = [
66
- "quote",
67
- "syn",
68
- ]
69
-
70
- [[package]]
71
- name = "either"
72
- version = "1.15.0"
73
- source = "registry+https://github.com/rust-lang/crates.io-index"
74
- checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
75
-
76
- [[package]]
77
- name = "ethnum"
78
- version = "1.5.2"
79
- source = "registry+https://github.com/rust-lang/crates.io-index"
80
- checksum = "ca81e6b4777c89fd810c25a4be2b1bd93ea034fbe58e6a75216a34c6b82c539b"
81
-
82
- [[package]]
83
- name = "itoa"
84
- version = "1.0.18"
85
- source = "registry+https://github.com/rust-lang/crates.io-index"
86
- checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
87
-
88
- [[package]]
89
- name = "libloading"
90
- version = "0.8.9"
91
- source = "registry+https://github.com/rust-lang/crates.io-index"
92
- checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
93
- dependencies = [
94
- "cfg-if",
95
- "windows-link",
96
- ]
97
-
98
- [[package]]
99
- name = "memchr"
100
- version = "2.8.0"
101
- source = "registry+https://github.com/rust-lang/crates.io-index"
102
- checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
103
-
104
- [[package]]
105
- name = "napi"
106
- version = "2.16.17"
107
- source = "registry+https://github.com/rust-lang/crates.io-index"
108
- checksum = "55740c4ae1d8696773c78fdafd5d0e5fe9bc9f1b071c7ba493ba5c413a9184f3"
109
- dependencies = [
110
- "bitflags",
111
- "ctor",
112
- "napi-derive",
113
- "napi-sys",
114
- "once_cell",
115
- "serde",
116
- "serde_json",
117
- ]
118
-
119
- [[package]]
120
- name = "napi-build"
121
- version = "2.3.1"
122
- source = "registry+https://github.com/rust-lang/crates.io-index"
123
- checksum = "d376940fd5b723c6893cd1ee3f33abbfd86acb1cd1ec079f3ab04a2a3bc4d3b1"
124
-
125
- [[package]]
126
- name = "napi-derive"
127
- version = "2.16.13"
128
- source = "registry+https://github.com/rust-lang/crates.io-index"
129
- checksum = "7cbe2585d8ac223f7d34f13701434b9d5f4eb9c332cccce8dee57ea18ab8ab0c"
130
- dependencies = [
131
- "cfg-if",
132
- "convert_case",
133
- "napi-derive-backend",
134
- "proc-macro2",
135
- "quote",
136
- "syn",
137
- ]
138
-
139
- [[package]]
140
- name = "napi-derive-backend"
141
- version = "1.0.75"
142
- source = "registry+https://github.com/rust-lang/crates.io-index"
143
- checksum = "1639aaa9eeb76e91c6ae66da8ce3e89e921cd3885e99ec85f4abacae72fc91bf"
144
- dependencies = [
145
- "convert_case",
146
- "once_cell",
147
- "proc-macro2",
148
- "quote",
149
- "regex",
150
- "semver",
151
- "syn",
152
- ]
153
-
154
- [[package]]
155
- name = "napi-sys"
156
- version = "2.4.0"
157
- source = "registry+https://github.com/rust-lang/crates.io-index"
158
- checksum = "427802e8ec3a734331fec1035594a210ce1ff4dc5bc1950530920ab717964ea3"
159
- dependencies = [
160
- "libloading",
161
- ]
162
-
163
- [[package]]
164
- name = "once_cell"
165
- version = "1.21.4"
166
- source = "registry+https://github.com/rust-lang/crates.io-index"
167
- checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
168
-
169
- [[package]]
170
- name = "proc-macro2"
171
- version = "1.0.106"
172
- source = "registry+https://github.com/rust-lang/crates.io-index"
173
- checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
174
- dependencies = [
175
- "unicode-ident",
176
- ]
177
-
178
- [[package]]
179
- name = "quote"
180
- version = "1.0.45"
181
- source = "registry+https://github.com/rust-lang/crates.io-index"
182
- checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
183
- dependencies = [
184
- "proc-macro2",
185
- ]
186
-
187
- [[package]]
188
- name = "rayon"
189
- version = "1.11.0"
190
- source = "registry+https://github.com/rust-lang/crates.io-index"
191
- checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f"
192
- dependencies = [
193
- "either",
194
- "rayon-core",
195
- ]
196
-
197
- [[package]]
198
- name = "rayon-core"
199
- version = "1.13.0"
200
- source = "registry+https://github.com/rust-lang/crates.io-index"
201
- checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
202
- dependencies = [
203
- "crossbeam-deque",
204
- "crossbeam-utils",
205
- ]
206
-
207
- [[package]]
208
- name = "regex"
209
- version = "1.12.3"
210
- source = "registry+https://github.com/rust-lang/crates.io-index"
211
- checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
212
- dependencies = [
213
- "aho-corasick",
214
- "memchr",
215
- "regex-automata",
216
- "regex-syntax",
217
- ]
218
-
219
- [[package]]
220
- name = "regex-automata"
221
- version = "0.4.14"
222
- source = "registry+https://github.com/rust-lang/crates.io-index"
223
- checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
224
- dependencies = [
225
- "aho-corasick",
226
- "memchr",
227
- "regex-syntax",
228
- ]
229
-
230
- [[package]]
231
- name = "regex-syntax"
232
- version = "0.8.10"
233
- source = "registry+https://github.com/rust-lang/crates.io-index"
234
- checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
235
-
236
- [[package]]
237
- name = "semver"
238
- version = "1.0.27"
239
- source = "registry+https://github.com/rust-lang/crates.io-index"
240
- checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
241
-
242
- [[package]]
243
- name = "serde"
244
- version = "1.0.228"
245
- source = "registry+https://github.com/rust-lang/crates.io-index"
246
- checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
247
- dependencies = [
248
- "serde_core",
249
- "serde_derive",
250
- ]
251
-
252
- [[package]]
253
- name = "serde_core"
254
- version = "1.0.228"
255
- source = "registry+https://github.com/rust-lang/crates.io-index"
256
- checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
257
- dependencies = [
258
- "serde_derive",
259
- ]
260
-
261
- [[package]]
262
- name = "serde_derive"
263
- version = "1.0.228"
264
- source = "registry+https://github.com/rust-lang/crates.io-index"
265
- checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
266
- dependencies = [
267
- "proc-macro2",
268
- "quote",
269
- "syn",
270
- ]
271
-
272
- [[package]]
273
- name = "serde_json"
274
- version = "1.0.149"
275
- source = "registry+https://github.com/rust-lang/crates.io-index"
276
- checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
277
- dependencies = [
278
- "itoa",
279
- "memchr",
280
- "serde",
281
- "serde_core",
282
- "zmij",
283
- ]
284
-
285
- [[package]]
286
- name = "syn"
287
- version = "2.0.117"
288
- source = "registry+https://github.com/rust-lang/crates.io-index"
289
- checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
290
- dependencies = [
291
- "proc-macro2",
292
- "quote",
293
- "unicode-ident",
294
- ]
295
-
296
- [[package]]
297
- name = "unicode-ident"
298
- version = "1.0.24"
299
- source = "registry+https://github.com/rust-lang/crates.io-index"
300
- checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
301
-
302
- [[package]]
303
- name = "unicode-segmentation"
304
- version = "1.13.2"
305
- source = "registry+https://github.com/rust-lang/crates.io-index"
306
- checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c"
307
-
308
- [[package]]
309
- name = "v3-math-native"
310
- version = "0.1.0"
311
- dependencies = [
312
- "ethnum",
313
- "napi",
314
- "napi-build",
315
- "napi-derive",
316
- "rayon",
317
- "serde",
318
- "serde_json",
319
- ]
320
-
321
- [[package]]
322
- name = "windows-link"
323
- version = "0.2.1"
324
- source = "registry+https://github.com/rust-lang/crates.io-index"
325
- checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
326
-
327
- [[package]]
328
- name = "zmij"
329
- version = "1.0.21"
330
- source = "registry+https://github.com/rust-lang/crates.io-index"
331
- checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
package/native/Cargo.toml DELETED
@@ -1,22 +0,0 @@
1
- [package]
2
- name = "v3-math-native"
3
- version = "0.1.0"
4
- edition = "2021"
5
-
6
- [lib]
7
- crate-type = ["cdylib"]
8
-
9
- [dependencies]
10
- napi = { version = "2", features = ["napi6", "serde-json"] }
11
- napi-derive = "2"
12
- ethnum = "1"
13
- rayon = "1"
14
- serde = { version = "1", features = ["derive"] }
15
- serde_json = "1"
16
-
17
- [build-dependencies]
18
- napi-build = "2"
19
-
20
- [profile.release]
21
- lto = true
22
- strip = "symbols"
package/native/build.rs DELETED
@@ -1,5 +0,0 @@
1
- extern crate napi_build;
2
-
3
- fn main() {
4
- napi_build::setup();
5
- }
@@ -1,32 +0,0 @@
1
- {
2
- "name": "@paraswap/v3-math-native",
3
- "version": "0.1.0",
4
- "lockfileVersion": 3,
5
- "requires": true,
6
- "packages": {
7
- "": {
8
- "name": "@paraswap/v3-math-native",
9
- "version": "0.1.0",
10
- "devDependencies": {
11
- "@napi-rs/cli": "^2.18.0"
12
- }
13
- },
14
- "node_modules/@napi-rs/cli": {
15
- "version": "2.18.4",
16
- "resolved": "https://registry.npmjs.org/@napi-rs/cli/-/cli-2.18.4.tgz",
17
- "integrity": "sha512-SgJeA4df9DE2iAEpr3M2H0OKl/yjtg1BnRI5/JyowS71tUWhrfSu2LT0V3vlHET+g1hBVlrO60PmEXwUEKp8Mg==",
18
- "dev": true,
19
- "license": "MIT",
20
- "bin": {
21
- "napi": "scripts/index.js"
22
- },
23
- "engines": {
24
- "node": ">= 10"
25
- },
26
- "funding": {
27
- "type": "github",
28
- "url": "https://github.com/sponsors/Brooooooklyn"
29
- }
30
- }
31
- }
32
- }
@@ -1,20 +0,0 @@
1
- {
2
- "name": "@paraswap/v3-math-native",
3
- "version": "0.1.0",
4
- "private": true,
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "napi": {
8
- "name": "v3-math-native",
9
- "triples": {
10
- "defaults": true
11
- }
12
- },
13
- "scripts": {
14
- "build": "napi build --platform --release",
15
- "build:debug": "napi build --platform"
16
- },
17
- "devDependencies": {
18
- "@napi-rs/cli": "^2.18.0"
19
- }
20
- }
@@ -1,73 +0,0 @@
1
- /// Configures math variant differences between Uniswap V3 forks.
2
- #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3
- pub enum MathVariant {
4
- /// Standard Uniswap V3: feeProtocol is 4-bit (% 16 / >> 4)
5
- UniswapV3,
6
- /// PancakeSwap V3: feeProtocol is 16-bit (% 65536 / >> 16), delta = feeAmount * fp / 10000
7
- PancakeSwapV3,
8
- /// Solidly V3: No oracle, no feeProtocol, fee from slot0.fee
9
- SolidlyV3,
10
- }
11
-
12
- impl MathVariant {
13
- pub fn from_str(s: &str) -> Self {
14
- match s {
15
- "pancakeswap_v3" => MathVariant::PancakeSwapV3,
16
- "solidly_v3" => MathVariant::SolidlyV3,
17
- _ => MathVariant::UniswapV3,
18
- }
19
- }
20
-
21
- /// Extract the fee protocol value for the given swap direction.
22
- pub fn fee_protocol(
23
- &self,
24
- fee_protocol_raw: ethnum::U256,
25
- zero_for_one: bool,
26
- ) -> ethnum::U256 {
27
- match self {
28
- MathVariant::SolidlyV3 => ethnum::U256::ZERO, // no protocol fee
29
- MathVariant::UniswapV3 => {
30
- if zero_for_one {
31
- fee_protocol_raw % ethnum::U256::from(16u32)
32
- } else {
33
- fee_protocol_raw >> 4
34
- }
35
- }
36
- MathVariant::PancakeSwapV3 => {
37
- if zero_for_one {
38
- fee_protocol_raw % ethnum::U256::from(65536u32)
39
- } else {
40
- fee_protocol_raw >> 16
41
- }
42
- }
43
- }
44
- }
45
-
46
- /// Calculate protocol fee delta from fee amount.
47
- /// V3: delta = feeAmount / feeProtocol
48
- /// PancakeSwap: delta = (feeAmount * feeProtocol) / 10000
49
- pub fn protocol_fee_delta(
50
- &self,
51
- fee_amount: ethnum::U256,
52
- fee_protocol: ethnum::U256,
53
- ) -> ethnum::U256 {
54
- match self {
55
- MathVariant::SolidlyV3 => ethnum::U256::ZERO,
56
- MathVariant::UniswapV3 => fee_amount / fee_protocol,
57
- MathVariant::PancakeSwapV3 => {
58
- (fee_amount * fee_protocol) / ethnum::U256::from(10000u32)
59
- }
60
- }
61
- }
62
-
63
- /// Whether this variant uses oracle observations.
64
- pub fn has_oracle(&self) -> bool {
65
- !matches!(self, MathVariant::SolidlyV3)
66
- }
67
-
68
- /// PancakeSwap V3 and Solidly V3 zero out remaining amounts for BOTH sell and buy at end of cycles.
69
- /// V3 only zeros for BUY.
70
- pub fn zero_remaining_for_sell(&self) -> bool {
71
- matches!(self, MathVariant::SolidlyV3 | MathVariant::PancakeSwapV3)
72
- }
73
- }