@reptilianhq/uniswap-sdk 0.3.0 → 0.4.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/dist/abis.d.ts +55 -0
- package/dist/abis.d.ts.map +1 -1
- package/dist/abis.js +6 -0
- package/dist/abis.js.map +1 -1
- package/dist/official-sdk.cjs +5 -1
- package/dist/official-sdk.cjs.map +1 -1
- package/dist/official-sdk.d.cts +2 -1
- package/dist/official-sdk.d.cts.map +1 -1
- package/dist/v4-transactions.d.ts +47 -0
- package/dist/v4-transactions.d.ts.map +1 -0
- package/dist/v4-transactions.js +57 -0
- package/dist/v4-transactions.js.map +1 -0
- package/dist/v4.d.ts +2 -0
- package/dist/v4.d.ts.map +1 -1
- package/dist/v4.js +1 -0
- package/dist/v4.js.map +1 -1
- package/package.json +2 -2
package/dist/abis.d.ts
CHANGED
|
@@ -157,5 +157,60 @@ export declare const v4PoolManagerAbi: readonly [{
|
|
|
157
157
|
readonly name: "tick";
|
|
158
158
|
}];
|
|
159
159
|
}];
|
|
160
|
+
export declare const v4PositionManagerAbi: readonly [{
|
|
161
|
+
readonly name: "initializePool";
|
|
162
|
+
readonly type: "function";
|
|
163
|
+
readonly stateMutability: "payable";
|
|
164
|
+
readonly inputs: readonly [{
|
|
165
|
+
readonly type: "tuple";
|
|
166
|
+
readonly components: readonly [{
|
|
167
|
+
readonly type: "address";
|
|
168
|
+
readonly name: "currency0";
|
|
169
|
+
}, {
|
|
170
|
+
readonly type: "address";
|
|
171
|
+
readonly name: "currency1";
|
|
172
|
+
}, {
|
|
173
|
+
readonly type: "uint24";
|
|
174
|
+
readonly name: "fee";
|
|
175
|
+
}, {
|
|
176
|
+
readonly type: "int24";
|
|
177
|
+
readonly name: "tickSpacing";
|
|
178
|
+
}, {
|
|
179
|
+
readonly type: "address";
|
|
180
|
+
readonly name: "hooks";
|
|
181
|
+
}];
|
|
182
|
+
readonly name: "key";
|
|
183
|
+
}, {
|
|
184
|
+
readonly type: "uint160";
|
|
185
|
+
readonly name: "sqrtPriceX96";
|
|
186
|
+
}];
|
|
187
|
+
readonly outputs: readonly [{
|
|
188
|
+
readonly type: "int24";
|
|
189
|
+
}];
|
|
190
|
+
}, {
|
|
191
|
+
readonly name: "modifyLiquidities";
|
|
192
|
+
readonly type: "function";
|
|
193
|
+
readonly stateMutability: "payable";
|
|
194
|
+
readonly inputs: readonly [{
|
|
195
|
+
readonly type: "bytes";
|
|
196
|
+
readonly name: "unlockData";
|
|
197
|
+
}, {
|
|
198
|
+
readonly type: "uint256";
|
|
199
|
+
readonly name: "deadline";
|
|
200
|
+
}];
|
|
201
|
+
readonly outputs: readonly [];
|
|
202
|
+
}, {
|
|
203
|
+
readonly name: "multicall";
|
|
204
|
+
readonly type: "function";
|
|
205
|
+
readonly stateMutability: "payable";
|
|
206
|
+
readonly inputs: readonly [{
|
|
207
|
+
readonly type: "bytes[]";
|
|
208
|
+
readonly name: "data";
|
|
209
|
+
}];
|
|
210
|
+
readonly outputs: readonly [{
|
|
211
|
+
readonly type: "bytes[]";
|
|
212
|
+
readonly name: "results";
|
|
213
|
+
}];
|
|
214
|
+
}];
|
|
160
215
|
export * from './v3-abis.js';
|
|
161
216
|
//# sourceMappingURL=abis.d.ts.map
|
package/dist/abis.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
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;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAK/B,CAAC;AAEH,cAAc,cAAc,CAAC"}
|
package/dist/abis.js
CHANGED
|
@@ -17,5 +17,11 @@ export const v4QuoterAbi = parseAbi([
|
|
|
17
17
|
export const v4PoolManagerAbi = parseAbi([
|
|
18
18
|
'event Initialize(bytes32 indexed id, address indexed currency0, address indexed currency1, uint24 fee, int24 tickSpacing, address hooks, uint160 sqrtPriceX96, int24 tick)',
|
|
19
19
|
]);
|
|
20
|
+
export const v4PositionManagerAbi = parseAbi([
|
|
21
|
+
'struct PoolKey { address currency0; address currency1; uint24 fee; int24 tickSpacing; address hooks; }',
|
|
22
|
+
'function initializePool(PoolKey key, uint160 sqrtPriceX96) payable returns (int24)',
|
|
23
|
+
'function modifyLiquidities(bytes unlockData, uint256 deadline) payable',
|
|
24
|
+
'function multicall(bytes[] data) payable returns (bytes[] results)',
|
|
25
|
+
]);
|
|
20
26
|
export * from './v3-abis.js';
|
|
21
27
|
//# sourceMappingURL=abis.js.map
|
package/dist/abis.js.map
CHANGED
|
@@ -1 +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"]}
|
|
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;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC3C,wGAAwG;IACxG,oFAAoF;IACpF,wEAAwE;IACxE,oEAAoE;CACrE,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]);\nexport const v4PositionManagerAbi = parseAbi([\n 'struct PoolKey { address currency0; address currency1; uint24 fee; int24 tickSpacing; address hooks; }',\n 'function initializePool(PoolKey key, uint160 sqrtPriceX96) payable returns (int24)',\n 'function modifyLiquidities(bytes unlockData, uint256 deadline) payable',\n 'function multicall(bytes[] data) payable returns (bytes[] results)',\n]);\n\nexport * from './v3-abis.js';\n"]}
|
package/dist/official-sdk.cjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Hook = exports.Pool = void 0;
|
|
3
|
+
exports.Percent = exports.V4PositionManager = exports.Position = exports.Hook = exports.Pool = void 0;
|
|
4
4
|
// Upstream 2.3.3's ESM export contains extensionless directory imports that
|
|
5
5
|
// native Node cannot resolve. Its public require export works in Node and
|
|
6
6
|
// bundlers. Keep this compatibility seam local instead of forking the SDK.
|
|
7
7
|
var v4_sdk_1 = require("@uniswap/v4-sdk");
|
|
8
8
|
Object.defineProperty(exports, "Pool", { enumerable: true, get: function () { return v4_sdk_1.Pool; } });
|
|
9
9
|
Object.defineProperty(exports, "Hook", { enumerable: true, get: function () { return v4_sdk_1.Hook; } });
|
|
10
|
+
Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return v4_sdk_1.Position; } });
|
|
11
|
+
Object.defineProperty(exports, "V4PositionManager", { enumerable: true, get: function () { return v4_sdk_1.V4PositionManager; } });
|
|
12
|
+
var sdk_core_1 = require("@uniswap/sdk-core");
|
|
13
|
+
Object.defineProperty(exports, "Percent", { enumerable: true, get: function () { return sdk_core_1.Percent; } });
|
|
10
14
|
//# sourceMappingURL=official-sdk.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"official-sdk.cjs","sourceRoot":"","sources":["../src/official-sdk.cts"],"names":[],"mappings":";;;AAAA,4EAA4E;AAC5E,0EAA0E;AAC1E,2EAA2E;AAC3E,
|
|
1
|
+
{"version":3,"file":"official-sdk.cjs","sourceRoot":"","sources":["../src/official-sdk.cts"],"names":[],"mappings":";;;AAAA,4EAA4E;AAC5E,0EAA0E;AAC1E,2EAA2E;AAC3E,0CAA0E;AAAjE,8FAAA,IAAI,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAChD,8CAA4C;AAAnC,mGAAA,OAAO,OAAA","sourcesContent":["// Upstream 2.3.3's ESM export contains extensionless directory imports that\n// native Node cannot resolve. Its public require export works in Node and\n// bundlers. Keep this compatibility seam local instead of forking the SDK.\nexport { Pool, Hook, Position, V4PositionManager } from '@uniswap/v4-sdk';\nexport { Percent } from '@uniswap/sdk-core';\n"]}
|
package/dist/official-sdk.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"official-sdk.d.cts","sourceRoot":"","sources":["../src/official-sdk.cts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"official-sdk.d.cts","sourceRoot":"","sources":["../src/official-sdk.cts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Currency } from '@uniswap/sdk-core';
|
|
2
|
+
import type { Address, Hex } from 'viem';
|
|
3
|
+
export type V4TransactionMaterial = {
|
|
4
|
+
to: Address;
|
|
5
|
+
data: Hex;
|
|
6
|
+
value: bigint;
|
|
7
|
+
};
|
|
8
|
+
/** Pool state as read from PoolManager/StateView (e.g. via `readV4Pool`), not yet a mint target. */
|
|
9
|
+
export type V4PoolState = {
|
|
10
|
+
currency0: Currency;
|
|
11
|
+
currency1: Currency;
|
|
12
|
+
fee: number;
|
|
13
|
+
tickSpacing: number;
|
|
14
|
+
hooks: Address;
|
|
15
|
+
sqrtPriceX96: bigint;
|
|
16
|
+
liquidity: bigint;
|
|
17
|
+
tickCurrent: number;
|
|
18
|
+
};
|
|
19
|
+
export type V4MintPositionParams = {
|
|
20
|
+
positionManager: Address;
|
|
21
|
+
pool: V4PoolState;
|
|
22
|
+
tickLower: number;
|
|
23
|
+
tickUpper: number;
|
|
24
|
+
/** Liquidity units to mint, not a token amount. */
|
|
25
|
+
liquidity: bigint;
|
|
26
|
+
recipient: Address;
|
|
27
|
+
/** Integer basis points, 0-10000. */
|
|
28
|
+
slippageToleranceBps: number;
|
|
29
|
+
deadlineSeconds: bigint;
|
|
30
|
+
/** Passed to the hook's callbacks verbatim; this SDK does not construct it. */
|
|
31
|
+
hookData?: Hex;
|
|
32
|
+
/** Atomically initializes the pool before minting. Requires `pool.sqrtPriceX96` to be the intended starting price. */
|
|
33
|
+
createPool?: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Builds unsigned calldata for `PositionManager.modifyLiquidities` minting a new v4 position.
|
|
37
|
+
* Delegates encoding to `@uniswap/v4-sdk`'s `V4PositionManager`/`V4PositionPlanner` (the same
|
|
38
|
+
* Actions/multicall encoding Uniswap's own SDK uses) rather than hand-rolling it, since v4's
|
|
39
|
+
* calldata is a sequence of packed actions, not a single ABI-encoded function call like v3's.
|
|
40
|
+
*
|
|
41
|
+
* No Permit2 support yet — callers must have already approved the position manager via a plain
|
|
42
|
+
* ERC20 approval, or the built transaction will revert on-chain. Hook-permission gating (refusing
|
|
43
|
+
* a pool whose hook implements more than the caller has modelled) is also the caller's
|
|
44
|
+
* responsibility; this function only encodes what it is given.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildV4MintPositionTransaction(input: V4MintPositionParams): V4TransactionMaterial;
|
|
47
|
+
//# sourceMappingURL=v4-transactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v4-transactions.d.ts","sourceRoot":"","sources":["../src/v4-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAKzC,MAAM,MAAM,qBAAqB,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E,oGAAoG;AACpG,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,QAAQ,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,sHAAsH;IACtH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AASF;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,oBAAoB,GAAG,qBAAqB,CAyCjG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Percent, Pool, Position, V4PositionManager } from './official-sdk.cjs';
|
|
2
|
+
import { checkedAddress } from './pool.js';
|
|
3
|
+
import { invalid, UniswapSdkError } from './errors.js';
|
|
4
|
+
function slippagePercent(bps) {
|
|
5
|
+
if (!Number.isInteger(bps) || bps < 0 || bps > 10_000) {
|
|
6
|
+
invalid('slippageToleranceBps must be an integer between 0 and 10000');
|
|
7
|
+
}
|
|
8
|
+
return new Percent(bps, 10_000);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Builds unsigned calldata for `PositionManager.modifyLiquidities` minting a new v4 position.
|
|
12
|
+
* Delegates encoding to `@uniswap/v4-sdk`'s `V4PositionManager`/`V4PositionPlanner` (the same
|
|
13
|
+
* Actions/multicall encoding Uniswap's own SDK uses) rather than hand-rolling it, since v4's
|
|
14
|
+
* calldata is a sequence of packed actions, not a single ABI-encoded function call like v3's.
|
|
15
|
+
*
|
|
16
|
+
* No Permit2 support yet — callers must have already approved the position manager via a plain
|
|
17
|
+
* ERC20 approval, or the built transaction will revert on-chain. Hook-permission gating (refusing
|
|
18
|
+
* a pool whose hook implements more than the caller has modelled) is also the caller's
|
|
19
|
+
* responsibility; this function only encodes what it is given.
|
|
20
|
+
*/
|
|
21
|
+
export function buildV4MintPositionTransaction(input) {
|
|
22
|
+
if (input.liquidity <= 0n)
|
|
23
|
+
invalid('Mint liquidity must be positive');
|
|
24
|
+
if (!Number.isInteger(input.tickLower) || !Number.isInteger(input.tickUpper) || input.tickLower >= input.tickUpper) {
|
|
25
|
+
invalid('tickLower must be an integer less than tickUpper');
|
|
26
|
+
}
|
|
27
|
+
if (input.createPool && input.pool.sqrtPriceX96 <= 0n)
|
|
28
|
+
invalid('createPool requires a positive initial sqrtPriceX96');
|
|
29
|
+
const positionManager = checkedAddress(input.positionManager);
|
|
30
|
+
const recipient = checkedAddress(input.recipient);
|
|
31
|
+
const slippageTolerance = slippagePercent(input.slippageToleranceBps);
|
|
32
|
+
try {
|
|
33
|
+
const pool = new Pool(input.pool.currency0, input.pool.currency1, input.pool.fee, input.pool.tickSpacing, checkedAddress(input.pool.hooks), input.pool.sqrtPriceX96.toString(), input.pool.liquidity.toString(), input.pool.tickCurrent);
|
|
34
|
+
const position = new Position({
|
|
35
|
+
pool,
|
|
36
|
+
liquidity: input.liquidity.toString(),
|
|
37
|
+
tickLower: input.tickLower,
|
|
38
|
+
tickUpper: input.tickUpper,
|
|
39
|
+
});
|
|
40
|
+
const params = V4PositionManager.addCallParameters(position, {
|
|
41
|
+
recipient,
|
|
42
|
+
createPool: input.createPool ?? false,
|
|
43
|
+
...(input.createPool ? { sqrtPriceX96: input.pool.sqrtPriceX96.toString() } : {}),
|
|
44
|
+
useNative: pool.currency0.isNative ? pool.currency0 : undefined,
|
|
45
|
+
slippageTolerance,
|
|
46
|
+
hookData: input.hookData,
|
|
47
|
+
deadline: input.deadlineSeconds.toString(),
|
|
48
|
+
});
|
|
49
|
+
return { to: positionManager, data: params.calldata, value: BigInt(params.value) };
|
|
50
|
+
}
|
|
51
|
+
catch (cause) {
|
|
52
|
+
if (cause instanceof UniswapSdkError)
|
|
53
|
+
throw cause;
|
|
54
|
+
throw new UniswapSdkError('INVALID_ARGUMENT', 'Official Uniswap SDK rejected the mint parameters', { cause });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=v4-transactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v4-transactions.js","sourceRoot":"","sources":["../src/v4-transactions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAiCvD,SAAS,eAAe,CAAC,GAAW;IAClC,IAAI,CAAC,MAAM,CA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, Position, V4PositionManager } from './official-sdk.cjs';\nimport { checkedAddress } from './pool.js';\nimport { invalid, UniswapSdkError } from './errors.js';\n\nexport type V4TransactionMaterial = { to: Address; data: Hex; value: bigint };\n\n/** Pool state as read from PoolManager/StateView (e.g. via `readV4Pool`), not yet a mint target. */\nexport type V4PoolState = {\n currency0: Currency;\n currency1: Currency;\n fee: number;\n tickSpacing: number;\n hooks: Address;\n sqrtPriceX96: bigint;\n liquidity: bigint;\n tickCurrent: number;\n};\n\nexport type V4MintPositionParams = {\n positionManager: Address;\n pool: V4PoolState;\n tickLower: number;\n tickUpper: number;\n /** Liquidity units to mint, not a token amount. */\n liquidity: bigint;\n recipient: Address;\n /** Integer basis points, 0-10000. */\n slippageToleranceBps: number;\n deadlineSeconds: bigint;\n /** Passed to the hook's callbacks verbatim; this SDK does not construct it. */\n hookData?: Hex;\n /** Atomically initializes the pool before minting. Requires `pool.sqrtPriceX96` to be the intended starting price. */\n createPool?: boolean;\n};\n\nfunction slippagePercent(bps: number): Percent {\n if (!Number.isInteger(bps) || bps < 0 || bps > 10_000) {\n invalid('slippageToleranceBps must be an integer between 0 and 10000');\n }\n return new Percent(bps, 10_000);\n}\n\n/**\n * Builds unsigned calldata for `PositionManager.modifyLiquidities` minting a new v4 position.\n * Delegates encoding to `@uniswap/v4-sdk`'s `V4PositionManager`/`V4PositionPlanner` (the same\n * Actions/multicall encoding Uniswap's own SDK uses) rather than hand-rolling it, since v4's\n * calldata is a sequence of packed actions, not a single ABI-encoded function call like v3's.\n *\n * No Permit2 support yet — callers must have already approved the position manager via a plain\n * ERC20 approval, or the built transaction will revert on-chain. Hook-permission gating (refusing\n * a pool whose hook implements more than the caller has modelled) is also the caller's\n * responsibility; this function only encodes what it is given.\n */\nexport function buildV4MintPositionTransaction(input: V4MintPositionParams): V4TransactionMaterial {\n if (input.liquidity <= 0n) invalid('Mint liquidity must be positive');\n if (!Number.isInteger(input.tickLower) || !Number.isInteger(input.tickUpper) || input.tickLower >= input.tickUpper) {\n invalid('tickLower must be an integer less than tickUpper');\n }\n if (input.createPool && input.pool.sqrtPriceX96 <= 0n) invalid('createPool requires a positive initial sqrtPriceX96');\n const positionManager = checkedAddress(input.positionManager);\n const recipient = checkedAddress(input.recipient);\n const slippageTolerance = slippagePercent(input.slippageToleranceBps);\n\n try {\n const pool = new Pool(\n input.pool.currency0,\n input.pool.currency1,\n input.pool.fee,\n input.pool.tickSpacing,\n checkedAddress(input.pool.hooks),\n input.pool.sqrtPriceX96.toString(),\n input.pool.liquidity.toString(),\n input.pool.tickCurrent,\n );\n const position = new Position({\n pool,\n liquidity: input.liquidity.toString(),\n tickLower: input.tickLower,\n tickUpper: input.tickUpper,\n });\n const params = V4PositionManager.addCallParameters(position, {\n recipient,\n createPool: input.createPool ?? false,\n ...(input.createPool ? { sqrtPriceX96: input.pool.sqrtPriceX96.toString() } : {}),\n useNative: pool.currency0.isNative ? pool.currency0 : undefined,\n slippageTolerance,\n hookData: input.hookData,\n deadline: input.deadlineSeconds.toString(),\n });\n return { to: positionManager, data: params.calldata as Hex, value: BigInt(params.value) };\n } catch (cause) {\n if (cause instanceof UniswapSdkError) throw cause;\n throw new UniswapSdkError('INVALID_ARGUMENT', 'Official Uniswap SDK rejected the mint parameters', { cause });\n }\n}\n"]}
|
package/dist/v4.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ export type { V4Tick, V4TickWindow } from './depth.js';
|
|
|
7
7
|
export { decodeV4PoolInitialization } from './events.js';
|
|
8
8
|
export { decodeV4HookPermissions, unmodelledV4HookPermissions } from './hooks.js';
|
|
9
9
|
export type { V4HookPermissions } from './hooks.js';
|
|
10
|
+
export { buildV4MintPositionTransaction } from './v4-transactions.js';
|
|
11
|
+
export type { V4MintPositionParams, V4PoolState, V4TransactionMaterial } from './v4-transactions.js';
|
|
10
12
|
//# sourceMappingURL=v4.d.ts.map
|
package/dist/v4.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v4.d.ts","source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,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAClF,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AACtE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/v4.js
CHANGED
|
@@ -3,4 +3,5 @@ export { readV4Pool, quoteV4ExactInput, quoteV4Batch, verifyV4DeploymentWiring }
|
|
|
3
3
|
export { readV4TickWindow, ticksInWord } from './depth.js';
|
|
4
4
|
export { decodeV4PoolInitialization } from './events.js';
|
|
5
5
|
export { decodeV4HookPermissions, unmodelledV4HookPermissions } from './hooks.js';
|
|
6
|
+
export { buildV4MintPositionTransaction } from './v4-transactions.js';
|
|
6
7
|
//# sourceMappingURL=v4.js.map
|
package/dist/v4.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v4.js","sourceRoot":"","sources":["../src/v4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEnG,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { poolKeyFromCurrencies, getV4PoolId, poolReference } from './pool.js';\nexport type { V4Deployment, V4PoolKey, V4PoolReference } from './pool.js';\nexport { readV4Pool, quoteV4ExactInput, quoteV4Batch, verifyV4DeploymentWiring } from './reads.js';\nexport type { V4ReadClient, V4Observation, V4PoolSnapshot, V4QuoteInput, V4Quote, V4QuoteResult } from './reads.js';\nexport { readV4TickWindow, ticksInWord } from './depth.js';\nexport type { V4Tick, V4TickWindow } from './depth.js';\nexport { decodeV4PoolInitialization } from './events.js';\nexport { decodeV4HookPermissions, unmodelledV4HookPermissions } from './hooks.js';\nexport type { V4HookPermissions } from './hooks.js';\n"]}
|
|
1
|
+
{"version":3,"file":"v4.js","sourceRoot":"","sources":["../src/v4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEnG,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAElF,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export { poolKeyFromCurrencies, getV4PoolId, poolReference } from './pool.js';\nexport type { V4Deployment, V4PoolKey, V4PoolReference } from './pool.js';\nexport { readV4Pool, quoteV4ExactInput, quoteV4Batch, verifyV4DeploymentWiring } from './reads.js';\nexport type { V4ReadClient, V4Observation, V4PoolSnapshot, V4QuoteInput, V4Quote, V4QuoteResult } from './reads.js';\nexport { readV4TickWindow, ticksInWord } from './depth.js';\nexport type { V4Tick, V4TickWindow } from './depth.js';\nexport { decodeV4PoolInitialization } from './events.js';\nexport { decodeV4HookPermissions, unmodelledV4HookPermissions } from './hooks.js';\nexport type { V4HookPermissions } from './hooks.js';\nexport { buildV4MintPositionTransaction } from './v4-transactions.js';\nexport type { V4MintPositionParams, V4PoolState, V4TransactionMaterial } from './v4-transactions.js';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reptilianhq/uniswap-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Deployment-explicit Uniswap observations and reviewed transaction material.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -119,6 +119,6 @@
|
|
|
119
119
|
"reptilianRelease": {
|
|
120
120
|
"schemaVersion": 1,
|
|
121
121
|
"group": "uniswap-sdk",
|
|
122
|
-
"sourceSha": "
|
|
122
|
+
"sourceSha": "c050f60c50fa89a88acb7976429b4c08a18fdc84"
|
|
123
123
|
}
|
|
124
124
|
}
|