@reptilianhq/uniswap-sdk 0.2.2

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 (89) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +4 -0
  3. package/README.md +176 -0
  4. package/RELEASING.md +114 -0
  5. package/dist/abis.d.ts +161 -0
  6. package/dist/abis.d.ts.map +1 -0
  7. package/dist/abis.js +21 -0
  8. package/dist/abis.js.map +1 -0
  9. package/dist/batch.d.ts +60 -0
  10. package/dist/batch.d.ts.map +1 -0
  11. package/dist/batch.js +157 -0
  12. package/dist/batch.js.map +1 -0
  13. package/dist/compatibility.d.ts +15 -0
  14. package/dist/compatibility.d.ts.map +1 -0
  15. package/dist/compatibility.js +57 -0
  16. package/dist/compatibility.js.map +1 -0
  17. package/dist/deployments.d.ts +27 -0
  18. package/dist/deployments.d.ts.map +1 -0
  19. package/dist/deployments.js +70 -0
  20. package/dist/deployments.js.map +1 -0
  21. package/dist/depth.d.ts +24 -0
  22. package/dist/depth.d.ts.map +1 -0
  23. package/dist/depth.js +65 -0
  24. package/dist/depth.js.map +1 -0
  25. package/dist/errors.d.ts +25 -0
  26. package/dist/errors.d.ts.map +1 -0
  27. package/dist/errors.js +32 -0
  28. package/dist/errors.js.map +1 -0
  29. package/dist/events.d.ts +23 -0
  30. package/dist/events.d.ts.map +1 -0
  31. package/dist/events.js +27 -0
  32. package/dist/events.js.map +1 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +4 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/official-sdk.cjs +9 -0
  38. package/dist/official-sdk.cjs.map +1 -0
  39. package/dist/official-sdk.d.cts +2 -0
  40. package/dist/official-sdk.d.cts.map +1 -0
  41. package/dist/pool.d.ts +30 -0
  42. package/dist/pool.d.ts.map +1 -0
  43. package/dist/pool.js +55 -0
  44. package/dist/pool.js.map +1 -0
  45. package/dist/providers.d.ts +59 -0
  46. package/dist/providers.d.ts.map +1 -0
  47. package/dist/providers.js +110 -0
  48. package/dist/providers.js.map +1 -0
  49. package/dist/reads.d.ts +61 -0
  50. package/dist/reads.d.ts.map +1 -0
  51. package/dist/reads.js +92 -0
  52. package/dist/reads.js.map +1 -0
  53. package/dist/receipts.d.ts +2 -0
  54. package/dist/receipts.d.ts.map +1 -0
  55. package/dist/receipts.js +2 -0
  56. package/dist/receipts.js.map +1 -0
  57. package/dist/transactions.d.ts +2 -0
  58. package/dist/transactions.d.ts.map +1 -0
  59. package/dist/transactions.js +2 -0
  60. package/dist/transactions.js.map +1 -0
  61. package/dist/v3-abis.d.ts +525 -0
  62. package/dist/v3-abis.d.ts.map +1 -0
  63. package/dist/v3-abis.js +43 -0
  64. package/dist/v3-abis.js.map +1 -0
  65. package/dist/v3-receipts.d.ts +28 -0
  66. package/dist/v3-receipts.d.ts.map +1 -0
  67. package/dist/v3-receipts.js +68 -0
  68. package/dist/v3-receipts.js.map +1 -0
  69. package/dist/v3-transactions.d.ts +107 -0
  70. package/dist/v3-transactions.d.ts.map +1 -0
  71. package/dist/v3-transactions.js +323 -0
  72. package/dist/v3-transactions.js.map +1 -0
  73. package/dist/v3.d.ts +6 -0
  74. package/dist/v3.d.ts.map +1 -0
  75. package/dist/v3.js +6 -0
  76. package/dist/v3.js.map +1 -0
  77. package/dist/v4.d.ts +8 -0
  78. package/dist/v4.d.ts.map +1 -0
  79. package/dist/v4.js +5 -0
  80. package/dist/v4.js.map +1 -0
  81. package/docs/FORK_TESTING.md +24 -0
  82. package/examples/read-only-consumer.mjs +59 -0
  83. package/fixtures/receipts/robinhood-mainnet-v3-lifecycle.json +84 -0
  84. package/fixtures/receipts/robinhood-mainnet-v3-mint.json +42 -0
  85. package/package.json +124 -0
  86. package/provenance/mainnet.json +33 -0
  87. package/provenance/testnet.json +33 -0
  88. package/scripts/check-conformance.mjs +191 -0
  89. package/scripts/verify-v3-deployments.mjs +23 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ReptilianHQ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ This SDK depends on the MIT-licensed official Uniswap SDK packages.
2
+ The official packages and their license notices remain in their distributions.
3
+ The runtime bridge uses the upstream public CommonJS export without modifying it.
4
+ Reptilian batch/read logic derives from ReptilianHQ/block-arb-bot.
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # Shared Uniswap protocol SDK
2
+
3
+ Reptilian-maintained integration SDK, released independently through GitHub Packages.
4
+ It owns Uniswap protocol mechanics: reviewed deployments, ABI encoding and decoding,
5
+ unsigned v3 transaction material, calldata review, receipt evidence, and v4 observations.
6
+ It never owns keys, authorization policy, transaction submission, persistence, or orchestration.
7
+
8
+ ## Capabilities and ownership
9
+
10
+ - `./v4`: full pool identity, Initialize-log normalization, pool state,
11
+ exact-input Quoter simulation, ordered quote batches, initialized tick windows.
12
+ - `./v3`: Robinhood v3 deployment identity, compatibility checks, unsigned
13
+ position transaction builders, strict calldata review, and receipt evidence.
14
+ - `./deployments`, `./compatibility`, `./transactions`, `./receipts`: stable
15
+ capability subpaths for the capital-moving v3 surface.
16
+ - `./batch`: host-owned multicall integration for quoting, state decoding, and tick discovery.
17
+ - `./abis`: minimal v3 and v4 ABI surface used by the package.
18
+ - `./errors`: stable error codes; JSON serialization omits underlying RPC errors,
19
+ which may contain credentials. The in-process `cause` is diagnostic only.
20
+
21
+ The official `@uniswap/v4-sdk` and `@uniswap/sdk-core` versions are pinned.
22
+ Currency normalization uses the official SDK. Pool ID encoding is checked
23
+ against it for native/ERC-20 pairs and fee modes. On-chain Quoter simulation is
24
+ used instead of offline SDK swap math because custom hooks can change results.
25
+ The pinned upstream ESM export contains imports native Node cannot resolve;
26
+ `official-sdk.cts` uses its public CommonJS export through a local compiled shim.
27
+ The runtime smoke test exercises built ESM exports without a bundler. No upstream
28
+ files are patched or forked.
29
+
30
+ Reads/quotes/tick discovery were extracted from the bot's `scanner.ts`, `abi.ts`
31
+ and `depth.ts` read patterns. They now require explicit deployments and preserve
32
+ currency roles, hook data, failures and observation blocks. The bot consumes this package through an exact release dependency. Its host owns
33
+ multicall transport and trading policy; this package owns protocol encoding and decoding.
34
+
35
+ ## Usage
36
+
37
+ Inject the caller's configured viem client. Reptilian continues to resolve its
38
+ chain and RPC through `@reptilianhq/evm-config`; this independent protocol SDK
39
+ does not depend on the platform configuration package.
40
+
41
+ ```ts
42
+ import { readV4Pool, quoteV4ExactInput } from '@reptilianhq/uniswap-sdk/v4';
43
+
44
+ const pool = await readV4Pool(publicClient, reviewedDeployment, poolKey);
45
+ const quote = await quoteV4ExactInput(publicClient, reviewedDeployment, poolKey, {
46
+ currencyIn, amountIn, account, hookData: protocolEncodedHookData,
47
+ }, { blockNumber: pool.blockNumber });
48
+ ```
49
+
50
+ V3 hosts select an exported reviewed deployment, verify it against their RPC,
51
+ then build unsigned transaction material. The host must independently authorize,
52
+ simulate, sign, submit, and reconcile that material.
53
+
54
+ ```ts
55
+ import {
56
+ buildV3IncreaseLiquidityTransaction,
57
+ reviewV3IncreaseLiquidityCalldata,
58
+ robinhoodUniswapV3Mainnet,
59
+ verifyUniswapV3Compatibility,
60
+ } from '@reptilianhq/uniswap-sdk/v3';
61
+
62
+ await verifyUniswapV3Compatibility(publicClient, robinhoodUniswapV3Mainnet);
63
+ const material = buildV3IncreaseLiquidityTransaction({
64
+ manager: robinhoodUniswapV3Mainnet.contracts.nonfungiblePositionManager,
65
+ params,
66
+ });
67
+ reviewV3IncreaseLiquidityCalldata(material.data, params.tokenId);
68
+ ```
69
+
70
+ A complete deterministic consumer example is available in
71
+ [`examples/read-only-consumer.mjs`](./examples/read-only-consumer.mjs). It uses
72
+ the published package subpaths and demonstrates a pool observation, a partial
73
+ tick result, and branching on `isUniswapSdkError`.
74
+
75
+ The v4 `reviewedDeployment` contains chainId, PoolManager, StateView and Quoter addresses.
76
+ There are no implicit v4 Robinhood or Arc deployments. Hosts own endpoint selection,
77
+ finality, capability policy and secret storage. For multicall consumers, use
78
+ `quoteV4WithBatch`, `v4PoolStateCalls`, `decodeV4PoolState`,
79
+ `readV4PoolStatesWithBatch`, and `readV4TicksWithBatch` from `./batch`.
80
+ Those helpers preserve the existing host's transport, block and sender context;
81
+ the host must check chain/deployment identity and Quoter multicall compatibility.
82
+
83
+ ## Observation and quote guarantees
84
+
85
+ The direct-client RPC operations check chain identity (the `./batch` host owns that check). Pool/tick reads check StateView's
86
+ PoolManager pointer; quotes check the Quoter pointer at the observation block.
87
+ `verifyV4DeploymentWiring` checks both pointers. This proves wiring only: a contract that
88
+ returns the expected pointer is not necessarily the reviewed implementation.
89
+ Source/code verification and hook-specific compatibility remain release gates.
90
+
91
+ All state calls in an operation use one block number. Quote batches use up to
92
+ four concurrent individual eth_calls by default (maximum 16; at most 256 quotes).
93
+ They preserve account context rather than putting an extra Multicall contract
94
+ between the caller and the Quoter. A quote failure is distinct from successful
95
+ zero output. Invalid item input yields a typed item failure; chain/RPC identity
96
+ errors abort the batch. Quotes expose the account, hookData, quoter, amount and
97
+ observation block so consumers can retain exact context.
98
+
99
+ A quote is an observation, not executable or durable authorization. The Quoter
100
+ may call hooks differently from the intended router or custom executor. Arc's
101
+ adapter must prove those semantics and simulate the complete final transaction
102
+ with its actual sender, approvals and hook data before a write can be supported.
103
+ Requote after approvals or changed state. Block-number pinning does not establish
104
+ finality or protect against a reorg; the host must select appropriate blocks.
105
+
106
+ Pool IDs are not globally unique: retain chainId, PoolManager, PoolKey and poolId.
107
+ Native currency remains address(0), distinct from wrapped native ERC-20.
108
+ Initialize logs must come from the configured manager and reproduce their pool
109
+ ID. The decoder does not prove receipt finality, chain provenance or ingestion
110
+ completeness; the indexer must supply canonical logs and handle reorgs.
111
+
112
+ Tick windows return raw initialized ticks, never executable depth. Scans are
113
+ limited to 16 bitmap words with at most 16 concurrent tick calls. A narrower
114
+ range or any failed bitmap/tick sets `partial: true` and records missing
115
+ coordinates. Consumers must not reconstruct complete depth from partial ticks.
116
+
117
+ The `./batch` helpers preserve legacy host behavior deliberately. Unlike direct
118
+ quotes, `quoteV4WithBatch` accepts zero input for sizing probes. Invalid input
119
+ rejects the whole helper call; only Quoter reverts and malformed Quoter responses
120
+ become item-level failures. `decodeV4PoolState` permits zero state for
121
+ uninitialized-pool probes. `readV4TicksWithBatch` accepts an explicit set of up
122
+ to 259 bitmap words and marks the result partial unless that set covers the full
123
+ usable range without failures. Batch transports must pin the block and preserve
124
+ the sender context themselves.
125
+
126
+ ## Verification and release boundary
127
+
128
+ CI runs the full check suite on Node 24 and 26 with npm 11.5.2. Node 24
129
+ remains the publication runtime and the minimum supported consumer version.
130
+
131
+ From this independent repository:
132
+
133
+ ```sh
134
+ npm ci --ignore-scripts
135
+ npm run check
136
+ ```
137
+
138
+ The local suite uses real viem ABI encoding/decoding over a deterministic RPC
139
+ transport, plus official SDK identity comparisons, Hegel property invariants,
140
+ and pinned finalized Robinhood mainnet receipt fixtures.
141
+ It covers v3 construction/review identity, manager-scoped receipt evidence, multiple chain
142
+ IDs, native/ERC-20 direction, dynamic-fee hook data, pointer/chain mismatch,
143
+ partial depth, failed versus zero quotes, discovery identity, batched transport
144
+ compatibility, exact reviewed runtime code hashes, and the runnable
145
+ package-subpath consumer example. `npm run test:fork` additionally executes an
146
+ SDK-built and reviewed full position close against the pinned Anvil fork
147
+ documented in [docs/FORK_TESTING.md](./docs/FORK_TESTING.md).
148
+
149
+ `npm run test:live-compatibility` rechecks both exported deployments against
150
+ their public RPCs. `UNISWAP_MAINNET_RPC_URL` and `UNISWAP_TESTNET_RPC_URL` may
151
+ override those read-only endpoints.
152
+
153
+ Releases use the versioned Reptilian publisher, exact main-ancestry tags,
154
+ immutable archive verification, and retained evidence; see [RELEASING.md](./RELEASING.md).
155
+ The v3 surface is capital-moving protocol support: it prepares unsigned calldata
156
+ and verifies protocol-specific transaction and receipt facts. It does not grant
157
+ authorization or submit transactions. The v4 surface remains read-only and does
158
+ not claim Arc deployment or custom-hook compatibility. Never treat a local test
159
+ or a successful wiring check as source verification.
160
+
161
+ Next: supply Arc contract/RPC details, verify code and hook/custody semantics,
162
+ then add its adapter and a tested managed-position lifecycle. Existing v3-only
163
+ application capability gates remain appropriate until that adapter is verified.
164
+
165
+ ## Protocol provider composition
166
+
167
+ `./providers` exports portable `V4ProviderDescriptor` and `V4ProviderPool` types,
168
+ structural verifiers, and `buildV4PoolSubscriptions`. Protocol SDKs own canonical
169
+ membership, reviewed deployment/hook semantics and position capabilities. The
170
+ shared planner checks complete identity and emits bounded event-topic requests
171
+ for explicitly selected pools. Empty selection returns no requests; transports
172
+ without indexed topic filtering are rejected.
173
+
174
+ Callers own RPC selection, finality, canonical membership storage and reorg
175
+ rollback. Replay the full discovery block. Structural checks cannot authenticate
176
+ arbitrary supplied membership evidence and never authorize execution.
package/RELEASING.md ADDED
@@ -0,0 +1,114 @@
1
+ # Uniswap SDK releases
2
+
3
+ This repository owns `@reptilianhq/uniswap-sdk`. Publish to the public npm
4
+ registry using the same Reptilian artifact publisher 1.2.2 used by the other
5
+ standalone package owners. `scripts/artifacts/publisher.lock.json` pins the
6
+ canonical publisher bytes; update them from the Reptilian root's vendor command.
7
+ Do not edit the emitted publisher locally.
8
+
9
+ ## One-time npm setup
10
+
11
+ The publish workflow authenticates via npm OIDC Trusted Publishing
12
+ (`id-token: write`, no static token). Trusted Publishing is configured on an
13
+ *existing* npm package, so it cannot be the very first thing you set up for a
14
+ scope that has never published:
15
+
16
+ 1. Create/claim the `@reptilianhq` org on npmjs.org if it does not exist yet.
17
+ 2. Land the version on `main` and push its tag (`uniswap-sdk-v0.2.2`, the
18
+ first version targeting the public registry) as usual. This triggers
19
+ `publish.yml` automatically — let it fail; Trusted Publishing cannot exist
20
+ yet, so it will error on a plain E401/E403. That is expected for the
21
+ bootstrap version only.
22
+ 3. Publish that same tagged version yourself with a temporary org-scoped
23
+ access token (a granular token cannot target a package that doesn't exist
24
+ yet), using the **Local fallback** publisher flow below (`publisher.mjs
25
+ prepare` then `publish`) — not a raw `npm publish`. `prepare` injects the
26
+ `reptilianRelease` manifest metadata and repacks the tarball; a
27
+ hand-published tarball would be missing that and would permanently fail
28
+ CI's immutable-byte check on every later run for that same version, since
29
+ the only recovery for a byte mismatch is a new numbered RC. The publisher
30
+ shells out to `npm publish`/`npm dist-tag` from a temp directory, so put
31
+ the token in `~/.npmrc` (or `NPM_CONFIG_//registry.npmjs.org/:_authToken`)
32
+ — this repo has no `.npmrc`, and one placed in the repo root would be
33
+ ignored. Revoke the token once this succeeds.
34
+ 4. On the package's npmjs.org settings, add this repository and
35
+ `.github/workflows/publish.yml` as a Trusted Publisher. Optionally scope
36
+ it to the `npm` GitHub environment name — matching `launch-on-block-sdk`
37
+ — but this is optional metadata on npm's side; leaving it unscoped works
38
+ too. Set the Trusted Publisher itself to **always publish** rather than
39
+ the staged/approval default — the publisher script
40
+ (`scripts/artifacts/publisher.mjs`) runs a plain `npm publish` with no
41
+ support for a staged-approval step, so a staged config will hang the
42
+ workflow.
43
+ 5. The `npm` GitHub environment referenced by the job does not need to exist
44
+ on this repo ahead of time; GitHub creates it automatically the first time
45
+ the workflow runs. **Leave it with no protection rules** (no required
46
+ reviewers, no wait timer) — `launch-on-block-sdk`'s own `npm` environment
47
+ has a required-reviewer rule, but copying that here would reintroduce the
48
+ same staged-approval hang from step 4, just via GitHub's environment gate
49
+ instead of npm's. `timeout-minutes: 30` on the job bounds execution time,
50
+ not an approval wait, so a gated run would park rather than fail loudly.
51
+
52
+ After that one-time setup, every subsequent release goes through the tagged
53
+ CI flow below with no token in the repository.
54
+
55
+ ## Release verification
56
+
57
+ Run `npm ci --ignore-scripts` and `npm run check`. Checks include TypeScript,
58
+ lint, unit tests, built Node ESM runtime smoke, a runnable consumer example using
59
+ the public package subpaths, publisher checksum and tests,
60
+ packed export lint, and packed ESM/type resolution. The published scope includes
61
+ v4 observations and provider plans plus v3 reviewed deployments, exact runtime
62
+ code hashes, unsigned transaction construction, calldata review, compatibility
63
+ checks, pinned receipt evidence, and a self-hash-checked copy of the shared SDK
64
+ conformance rules. Run `npm run test:fork` separately with an
65
+ archive-capable `SDK_FORK_EIP155_4663_RPC_URL`; it simulates and executes the
66
+ reviewed close path on a pinned Anvil fork, then requires the collected receipt
67
+ amounts to match the simulation. Run `npm run test:live-compatibility` before release to
68
+ recheck both deployment records. Runtime code identity is not source verification or
69
+ custom-hook compatibility. Arc details remain unavailable.
70
+
71
+ Set one exact version such as `<version>` in package.json and package-lock.json,
72
+ land the source on main, then push its immutable tag `uniswap-sdk-v<version>`.
73
+ The publish workflow verifies version identity and main ancestry, reruns package
74
+ checks, prepares archives and source metadata, publishes the archive without
75
+ rerunning lifecycle scripts, and verifies the registry metadata and downloaded
76
+ bytes. Numbered RCs use `rc`; stable releases use `latest`. Never move a tag,
77
+ overwrite bytes, or move a channel backwards.
78
+
79
+ Publication evidence is retained for 90 days as `release-record.json` and
80
+ `verification.json`. A manual dispatch with the same exact version retries the
81
+ same tag. Existing registry content must have matching source and archive bytes.
82
+ If it differs, fix the source and publish a new numbered RC.
83
+
84
+ On the public npm registry, automatic dist-tag/channel repair for an
85
+ interrupted publish (version published, channel not yet moved) is not
86
+ available — npm OIDC only authorizes the publish itself, not tag repair.
87
+ If a run is interrupted after the version lands but before its channel moves,
88
+ fix the dist-tag by hand (`npm dist-tag add <pkg>@<version> <channel>`) rather
89
+ than relying on retry. If OIDC authentication itself is misconfigured (no
90
+ Trusted Publisher entry for this repo/workflow, or it is set to staged
91
+ rather than always-publish), `npm publish` fails with a plain E401/E403 with
92
+ no specific OIDC diagnostic — check the npmjs.org package settings first.
93
+
94
+ ## Local fallback
95
+
96
+ When CI minutes are unavailable, run the same checks locally and use the same
97
+ publisher, from a clean tagged checkout with origin/main fetched:
98
+
99
+ ```sh
100
+ ARTIFACT_RELEASE_TAG=uniswap-sdk-v<version> node scripts/artifacts/publisher.mjs prepare uniswap-sdk .release
101
+ ARTIFACT_RELEASE_TAG=uniswap-sdk-v<version> node scripts/artifacts/publisher.mjs publish uniswap-sdk .release
102
+ ```
103
+
104
+ Registry credentials must already be configured; do not print tokens or put
105
+ them in committed configuration. Retain the two evidence files with the release.
106
+ The fallback does not relax tag, ancestry, version, or immutable-byte checks.
107
+
108
+ ## Consumer adoption
109
+
110
+ Consumers install an exact registry version and commit their lockfile. They must
111
+ not reference a sibling checkout, git branch, or vendored SDK tarball. Run the
112
+ bot's scanner/depth parity tests and browser build before promoting a new pin.
113
+ Host multicall policy remains explicit: the bot preserves its zero fallback for
114
+ failed sizing probes, while the SDK exposes those results as failures.
package/dist/abis.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ export declare const v4StateViewAbi: readonly [{
2
+ readonly name: "poolManager";
3
+ readonly type: "function";
4
+ readonly stateMutability: "view";
5
+ readonly inputs: readonly [];
6
+ readonly outputs: readonly [{
7
+ readonly type: "address";
8
+ }];
9
+ }, {
10
+ readonly name: "getSlot0";
11
+ readonly type: "function";
12
+ readonly stateMutability: "view";
13
+ readonly inputs: readonly [{
14
+ readonly type: "bytes32";
15
+ readonly name: "poolId";
16
+ }];
17
+ readonly outputs: readonly [{
18
+ readonly type: "uint160";
19
+ readonly name: "sqrtPriceX96";
20
+ }, {
21
+ readonly type: "int24";
22
+ readonly name: "tick";
23
+ }, {
24
+ readonly type: "uint24";
25
+ readonly name: "protocolFee";
26
+ }, {
27
+ readonly type: "uint24";
28
+ readonly name: "lpFee";
29
+ }];
30
+ }, {
31
+ readonly name: "getLiquidity";
32
+ readonly type: "function";
33
+ readonly stateMutability: "view";
34
+ readonly inputs: readonly [{
35
+ readonly type: "bytes32";
36
+ readonly name: "poolId";
37
+ }];
38
+ readonly outputs: readonly [{
39
+ readonly type: "uint128";
40
+ readonly name: "liquidity";
41
+ }];
42
+ }, {
43
+ readonly name: "getTickBitmap";
44
+ readonly type: "function";
45
+ readonly stateMutability: "view";
46
+ readonly inputs: readonly [{
47
+ readonly type: "bytes32";
48
+ readonly name: "poolId";
49
+ }, {
50
+ readonly type: "int16";
51
+ readonly name: "word";
52
+ }];
53
+ readonly outputs: readonly [{
54
+ readonly type: "uint256";
55
+ }];
56
+ }, {
57
+ readonly name: "getTickLiquidity";
58
+ readonly type: "function";
59
+ readonly stateMutability: "view";
60
+ readonly inputs: readonly [{
61
+ readonly type: "bytes32";
62
+ readonly name: "poolId";
63
+ }, {
64
+ readonly type: "int24";
65
+ readonly name: "tick";
66
+ }];
67
+ readonly outputs: readonly [{
68
+ readonly type: "uint128";
69
+ readonly name: "liquidityGross";
70
+ }, {
71
+ readonly type: "int128";
72
+ readonly name: "liquidityNet";
73
+ }];
74
+ }];
75
+ export declare const v4QuoterAbi: readonly [{
76
+ readonly name: "poolManager";
77
+ readonly type: "function";
78
+ readonly stateMutability: "view";
79
+ readonly inputs: readonly [];
80
+ readonly outputs: readonly [{
81
+ readonly type: "address";
82
+ }];
83
+ }, {
84
+ readonly name: "quoteExactInputSingle";
85
+ readonly type: "function";
86
+ readonly stateMutability: "nonpayable";
87
+ readonly inputs: readonly [{
88
+ readonly type: "tuple";
89
+ readonly components: readonly [{
90
+ readonly name: "poolKey";
91
+ readonly type: "tuple";
92
+ readonly components: readonly [{
93
+ readonly type: "address";
94
+ readonly name: "currency0";
95
+ }, {
96
+ readonly type: "address";
97
+ readonly name: "currency1";
98
+ }, {
99
+ readonly type: "uint24";
100
+ readonly name: "fee";
101
+ }, {
102
+ readonly type: "int24";
103
+ readonly name: "tickSpacing";
104
+ }, {
105
+ readonly type: "address";
106
+ readonly name: "hooks";
107
+ }];
108
+ }, {
109
+ readonly type: "bool";
110
+ readonly name: "zeroForOne";
111
+ }, {
112
+ readonly type: "uint128";
113
+ readonly name: "exactAmount";
114
+ }, {
115
+ readonly type: "bytes";
116
+ readonly name: "hookData";
117
+ }];
118
+ readonly name: "params";
119
+ }];
120
+ readonly outputs: readonly [{
121
+ readonly type: "uint256";
122
+ readonly name: "amountOut";
123
+ }, {
124
+ readonly type: "uint256";
125
+ readonly name: "gasEstimate";
126
+ }];
127
+ }];
128
+ export declare const v4PoolManagerAbi: readonly [{
129
+ readonly name: "Initialize";
130
+ readonly type: "event";
131
+ readonly inputs: readonly [{
132
+ readonly type: "bytes32";
133
+ readonly name: "id";
134
+ readonly indexed: true;
135
+ }, {
136
+ readonly type: "address";
137
+ readonly name: "currency0";
138
+ readonly indexed: true;
139
+ }, {
140
+ readonly type: "address";
141
+ readonly name: "currency1";
142
+ readonly indexed: true;
143
+ }, {
144
+ readonly type: "uint24";
145
+ readonly name: "fee";
146
+ }, {
147
+ readonly type: "int24";
148
+ readonly name: "tickSpacing";
149
+ }, {
150
+ readonly type: "address";
151
+ readonly name: "hooks";
152
+ }, {
153
+ readonly type: "uint160";
154
+ readonly name: "sqrtPriceX96";
155
+ }, {
156
+ readonly type: "int24";
157
+ readonly name: "tick";
158
+ }];
159
+ }];
160
+ export * from './v3-abis.js';
161
+ //# sourceMappingURL=abis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abis.d.ts","sourceRoot":"","sources":["../src/abis.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMzB,CAAC;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKtB,CAAC;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE3B,CAAC;AAEH,cAAc,cAAc,CAAC"}
package/dist/abis.js ADDED
@@ -0,0 +1,21 @@
1
+ import { parseAbi } from 'viem';
2
+ // Standard v4-core/periphery selectors; extracted from the bot's read surface.
3
+ // They do not attest compatibility of a supplied custom deployment.
4
+ export const v4StateViewAbi = parseAbi([
5
+ 'function poolManager() view returns (address)',
6
+ 'function getSlot0(bytes32 poolId) view returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)',
7
+ 'function getLiquidity(bytes32 poolId) view returns (uint128 liquidity)',
8
+ 'function getTickBitmap(bytes32 poolId, int16 word) view returns (uint256)',
9
+ 'function getTickLiquidity(bytes32 poolId, int24 tick) view returns (uint128 liquidityGross, int128 liquidityNet)',
10
+ ]);
11
+ export const v4QuoterAbi = parseAbi([
12
+ 'function poolManager() view returns (address)',
13
+ 'struct PoolKey { address currency0; address currency1; uint24 fee; int24 tickSpacing; address hooks; }',
14
+ 'struct QuoteExactSingleParams { PoolKey poolKey; bool zeroForOne; uint128 exactAmount; bytes hookData; }',
15
+ 'function quoteExactInputSingle(QuoteExactSingleParams params) returns (uint256 amountOut, uint256 gasEstimate)',
16
+ ]);
17
+ export const v4PoolManagerAbi = parseAbi([
18
+ 'event Initialize(bytes32 indexed id, address indexed currency0, address indexed currency1, uint24 fee, int24 tickSpacing, address hooks, uint160 sqrtPriceX96, int24 tick)',
19
+ ]);
20
+ export * from './v3-abis.js';
21
+ //# sourceMappingURL=abis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abis.js","sourceRoot":"","sources":["../src/abis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEhC,+EAA+E;AAC/E,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;IACrC,+CAA+C;IAC/C,qHAAqH;IACrH,wEAAwE;IACxE,2EAA2E;IAC3E,kHAAkH;CACnH,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC;IAClC,+CAA+C;IAC/C,wGAAwG;IACxG,0GAA0G;IAC1G,gHAAgH;CACjH,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACvC,4KAA4K;CAC7K,CAAC,CAAC;AAEH,cAAc,cAAc,CAAC","sourcesContent":["import { parseAbi } from 'viem';\n\n// Standard v4-core/periphery selectors; extracted from the bot's read surface.\n// They do not attest compatibility of a supplied custom deployment.\nexport const v4StateViewAbi = parseAbi([\n 'function poolManager() view returns (address)',\n 'function getSlot0(bytes32 poolId) view returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)',\n 'function getLiquidity(bytes32 poolId) view returns (uint128 liquidity)',\n 'function getTickBitmap(bytes32 poolId, int16 word) view returns (uint256)',\n 'function getTickLiquidity(bytes32 poolId, int24 tick) view returns (uint128 liquidityGross, int128 liquidityNet)',\n]);\nexport const v4QuoterAbi = parseAbi([\n 'function poolManager() view returns (address)',\n 'struct PoolKey { address currency0; address currency1; uint24 fee; int24 tickSpacing; address hooks; }',\n 'struct QuoteExactSingleParams { PoolKey poolKey; bool zeroForOne; uint128 exactAmount; bytes hookData; }',\n 'function quoteExactInputSingle(QuoteExactSingleParams params) returns (uint256 amountOut, uint256 gasEstimate)',\n]);\nexport const v4PoolManagerAbi = parseAbi([\n 'event Initialize(bytes32 indexed id, address indexed currency0, address indexed currency1, uint24 fee, int24 tickSpacing, address hooks, uint160 sqrtPriceX96, int24 tick)',\n]);\n\nexport * from './v3-abis.js';\n"]}
@@ -0,0 +1,60 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import { UniswapSdkError } from './errors.js';
3
+ import { type V4PoolKey } from './pool.js';
4
+ /** Host-owned batch transport. Host owns chain/wiring checks, block pinning and sender. */
5
+ export interface V4BatchCall {
6
+ target: Address;
7
+ allowFailure: boolean;
8
+ callData: Hex;
9
+ }
10
+ export interface V4BatchResult {
11
+ success: boolean;
12
+ returnData: Hex;
13
+ }
14
+ export type V4BatchTransport = (calls: V4BatchCall[]) => Promise<readonly V4BatchResult[]>;
15
+ export interface V4PoolState {
16
+ sqrtPriceX96: bigint;
17
+ tick: number;
18
+ protocolFee: number;
19
+ lpFee: number;
20
+ liquidity: bigint;
21
+ }
22
+ export type V4BatchQuote = {
23
+ status: 'success';
24
+ amountOut: bigint;
25
+ gasEstimate: bigint;
26
+ } | {
27
+ status: 'failure';
28
+ error: UniswapSdkError;
29
+ };
30
+ /** Slot0 then liquidity; callers may combine these with other venues in one RPC. */
31
+ export declare function v4PoolStateCalls(stateView: Address, poolId: Hex): [V4BatchCall, V4BatchCall];
32
+ /** Zero state is valid for the bot's uninitialized-pool probes. */
33
+ export declare function decodeV4PoolState(results: readonly V4BatchResult[]): V4PoolState;
34
+ export declare function readV4PoolStatesWithBatch(transport: V4BatchTransport, stateView: Address, poolIds: readonly Hex[]): Promise<V4PoolState[]>;
35
+ /** Explicit multicall opt-in: hooks see the host's multicall/Quoter context. */
36
+ export declare function quoteV4WithBatch(transport: V4BatchTransport, quoter: Address, inputKey: V4PoolKey, inputs: readonly {
37
+ currencyIn: Address;
38
+ amountIn: bigint;
39
+ hookData: Hex;
40
+ }[]): Promise<V4BatchQuote[]>;
41
+ export declare const V4_MIN_TICK = -887272;
42
+ export declare const V4_MAX_TICK = 887272;
43
+ export declare function usableV4TickRange(tickSpacing: number): {
44
+ min: number;
45
+ max: number;
46
+ };
47
+ export declare function v4WordPosition(tick: number, tickSpacing: number): number;
48
+ /** Spot window plus the two extremes, retaining full-range LP boundary ticks. */
49
+ export declare function v4DepthWordPositions(currentTick: number, tickSpacing: number, radius: number): number[];
50
+ export declare function readV4TicksWithBatch(transport: V4BatchTransport, stateView: Address, poolId: Hex, tickSpacing: number, words: readonly number[]): Promise<{
51
+ ticks: {
52
+ tick: number;
53
+ liquidityGross: bigint;
54
+ liquidityNet: bigint;
55
+ }[];
56
+ failedWords: number[];
57
+ failedTicks: number[];
58
+ partial: boolean;
59
+ }>;
60
+ //# sourceMappingURL=batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAExF,OAAO,EAAW,eAAe,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAmC,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAG5E,2FAA2F;AAC3F,MAAM,WAAW,WAAW;IAAG,MAAM,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAA;CAAE;AACtF,MAAM,WAAW,aAAa;IAAG,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,GAAG,CAAA;CAAE;AACpE,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC;AAC3F,MAAM,WAAW,WAAW;IAAG,YAAY,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE;AAC1H,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CAAC;AAczI,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAO5F;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,WAAW,CAOhF;AAED,wBAAsB,yBAAyB,CAAC,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAQhJ;AAED,gFAAgF;AAChF,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,gBAAgB,EAC3B,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,SAAS;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAA;CAAE,EAAE,GAC1E,OAAO,CAAC,YAAY,EAAE,CAAC,CAuBzB;AAED,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,WAAW,SAAS,CAAC;AAClC,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM;;;EAGpD;AACD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAI/D;AACD,iFAAiF;AACjF,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAY5F;AAED,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE;;cAqB/H,MAAM;wBAAkB,MAAM;sBAAgB,MAAM;;;;;GAgB1E"}