@kittycorn-labs/v4-sdk 1.1.30 → 2.0.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.
Files changed (197) hide show
  1. package/README.md +9 -0
  2. package/dist/{PositionManager.d.ts → cjs/src/PositionManager.d.ts} +169 -169
  3. package/dist/cjs/src/PositionManager.js +242 -0
  4. package/dist/cjs/src/PositionManager.js.map +1 -0
  5. package/dist/cjs/src/abis/IMulticall.json +23 -0
  6. package/dist/{actionConstants.d.ts → cjs/src/actionConstants.d.ts} +1 -1
  7. package/dist/cjs/src/actionConstants.js +6 -0
  8. package/dist/cjs/src/actionConstants.js.map +1 -0
  9. package/dist/{entities → cjs/src/entities}/index.d.ts +4 -4
  10. package/dist/cjs/src/entities/index.js +8 -0
  11. package/dist/cjs/src/entities/index.js.map +1 -0
  12. package/dist/{entities → cjs/src/entities}/pool.d.ts +103 -103
  13. package/dist/cjs/src/entities/pool.js +196 -0
  14. package/dist/cjs/src/entities/pool.js.map +1 -0
  15. package/dist/{entities → cjs/src/entities}/position.d.ts +144 -144
  16. package/dist/cjs/src/entities/position.js +273 -0
  17. package/dist/cjs/src/entities/position.js.map +1 -0
  18. package/dist/{entities → cjs/src/entities}/route.d.ts +28 -28
  19. package/dist/cjs/src/entities/route.js +89 -0
  20. package/dist/cjs/src/entities/route.js.map +1 -0
  21. package/dist/{entities → cjs/src/entities}/trade.d.ts +220 -220
  22. package/dist/cjs/src/entities/trade.js +441 -0
  23. package/dist/cjs/src/entities/trade.js.map +1 -0
  24. package/dist/{index.d.ts → cjs/src/index.d.ts} +4 -4
  25. package/dist/cjs/src/index.js +8 -0
  26. package/dist/cjs/src/index.js.map +1 -0
  27. package/dist/{internalConstants.d.ts → cjs/src/internalConstants.d.ts} +46 -46
  28. package/dist/cjs/src/internalConstants.js +69 -0
  29. package/dist/cjs/src/internalConstants.js.map +1 -0
  30. package/dist/{multicall.d.ts → cjs/src/multicall.d.ts} +10 -10
  31. package/dist/cjs/src/multicall.js +26 -0
  32. package/dist/cjs/src/multicall.js.map +1 -0
  33. package/dist/cjs/src/tokenize.d.ts +17 -0
  34. package/dist/cjs/src/tokenize.js +42 -0
  35. package/dist/cjs/src/tokenize.js.map +1 -0
  36. package/dist/{utils → cjs/src/utils}/calldata.d.ts +20 -20
  37. package/dist/cjs/src/utils/calldata.js +20 -0
  38. package/dist/cjs/src/utils/calldata.js.map +1 -0
  39. package/dist/{utils → cjs/src/utils}/currencyMap.d.ts +2 -2
  40. package/dist/cjs/src/utils/currencyMap.js +15 -0
  41. package/dist/cjs/src/utils/currencyMap.js.map +1 -0
  42. package/dist/{utils → cjs/src/utils}/encodeRouteToPath.d.ts +10 -10
  43. package/dist/cjs/src/utils/encodeRouteToPath.js +26 -0
  44. package/dist/cjs/src/utils/encodeRouteToPath.js.map +1 -0
  45. package/dist/{utils → cjs/src/utils}/hook.d.ts +45 -45
  46. package/dist/cjs/src/utils/hook.js +97 -0
  47. package/dist/cjs/src/utils/hook.js.map +1 -0
  48. package/dist/{utils → cjs/src/utils}/index.d.ts +11 -11
  49. package/dist/cjs/src/utils/index.js +15 -0
  50. package/dist/cjs/src/utils/index.js.map +1 -0
  51. package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +4 -4
  52. package/dist/cjs/src/utils/pathCurrency.js +27 -0
  53. package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
  54. package/dist/{utils → cjs/src/utils}/positionManagerAbi.d.ts +102 -102
  55. package/dist/cjs/src/utils/positionManagerAbi.js +1318 -0
  56. package/dist/cjs/src/utils/positionManagerAbi.js.map +1 -0
  57. package/dist/{utils → cjs/src/utils}/priceTickConversions.d.ts +20 -20
  58. package/dist/cjs/src/utils/priceTickConversions.js +55 -0
  59. package/dist/cjs/src/utils/priceTickConversions.js.map +1 -0
  60. package/dist/{utils → cjs/src/utils}/sortsBefore.d.ts +2 -2
  61. package/dist/cjs/src/utils/sortsBefore.js +12 -0
  62. package/dist/cjs/src/utils/sortsBefore.js.map +1 -0
  63. package/dist/{utils → cjs/src/utils}/v4BaseActionsParser.d.ts +49 -45
  64. package/dist/cjs/src/utils/v4BaseActionsParser.js +193 -0
  65. package/dist/cjs/src/utils/v4BaseActionsParser.js.map +1 -0
  66. package/dist/{utils → cjs/src/utils}/v4Planner.d.ts +71 -55
  67. package/dist/cjs/src/utils/v4Planner.js +267 -0
  68. package/dist/cjs/src/utils/v4Planner.js.map +1 -0
  69. package/dist/{utils → cjs/src/utils}/v4PositionPlanner.d.ts +13 -12
  70. package/dist/cjs/src/utils/v4PositionPlanner.js +61 -0
  71. package/dist/cjs/src/utils/v4PositionPlanner.js.map +1 -0
  72. package/dist/esm/package.json +1 -0
  73. package/dist/esm/src/PositionManager.d.ts +169 -0
  74. package/dist/esm/src/PositionManager.js +237 -0
  75. package/dist/esm/src/PositionManager.js.map +1 -0
  76. package/dist/esm/src/abis/IMulticall.json +23 -0
  77. package/dist/esm/src/actionConstants.d.ts +1 -0
  78. package/dist/esm/src/actionConstants.js +3 -0
  79. package/dist/esm/src/actionConstants.js.map +1 -0
  80. package/dist/esm/src/entities/index.d.ts +4 -0
  81. package/dist/esm/src/entities/index.js +5 -0
  82. package/dist/esm/src/entities/index.js.map +1 -0
  83. package/dist/esm/src/entities/pool.d.ts +103 -0
  84. package/dist/esm/src/entities/pool.js +191 -0
  85. package/dist/esm/src/entities/pool.js.map +1 -0
  86. package/dist/esm/src/entities/position.d.ts +144 -0
  87. package/dist/esm/src/entities/position.js +268 -0
  88. package/dist/esm/src/entities/position.js.map +1 -0
  89. package/dist/esm/src/entities/route.d.ts +28 -0
  90. package/dist/esm/src/entities/route.js +84 -0
  91. package/dist/esm/src/entities/route.js.map +1 -0
  92. package/dist/esm/src/entities/trade.d.ts +220 -0
  93. package/dist/esm/src/entities/trade.js +435 -0
  94. package/dist/esm/src/entities/trade.js.map +1 -0
  95. package/dist/esm/src/index.d.ts +4 -0
  96. package/dist/esm/src/index.js +5 -0
  97. package/dist/esm/src/index.js.map +1 -0
  98. package/dist/esm/src/internalConstants.d.ts +46 -0
  99. package/dist/esm/src/internalConstants.js +65 -0
  100. package/dist/esm/src/internalConstants.js.map +1 -0
  101. package/dist/esm/src/multicall.d.ts +10 -0
  102. package/dist/esm/src/multicall.js +21 -0
  103. package/dist/esm/src/multicall.js.map +1 -0
  104. package/dist/esm/src/tokenize.d.ts +17 -0
  105. package/dist/esm/src/tokenize.js +37 -0
  106. package/dist/esm/src/tokenize.js.map +1 -0
  107. package/dist/esm/src/utils/calldata.d.ts +20 -0
  108. package/dist/esm/src/utils/calldata.js +15 -0
  109. package/dist/esm/src/utils/calldata.js.map +1 -0
  110. package/dist/esm/src/utils/currencyMap.d.ts +2 -0
  111. package/dist/esm/src/utils/currencyMap.js +11 -0
  112. package/dist/esm/src/utils/currencyMap.js.map +1 -0
  113. package/dist/esm/src/utils/encodeRouteToPath.d.ts +10 -0
  114. package/dist/esm/src/utils/encodeRouteToPath.js +22 -0
  115. package/dist/esm/src/utils/encodeRouteToPath.js.map +1 -0
  116. package/dist/esm/src/utils/hook.d.ts +45 -0
  117. package/dist/esm/src/utils/hook.js +92 -0
  118. package/dist/esm/src/utils/hook.js.map +1 -0
  119. package/dist/esm/src/utils/index.d.ts +11 -0
  120. package/dist/esm/src/utils/index.js +12 -0
  121. package/dist/esm/src/utils/index.js.map +1 -0
  122. package/dist/esm/src/utils/pathCurrency.d.ts +4 -0
  123. package/dist/esm/src/utils/pathCurrency.js +22 -0
  124. package/dist/esm/src/utils/pathCurrency.js.map +1 -0
  125. package/dist/esm/src/utils/positionManagerAbi.d.ts +102 -0
  126. package/dist/esm/src/utils/positionManagerAbi.js +1315 -0
  127. package/dist/esm/src/utils/positionManagerAbi.js.map +1 -0
  128. package/dist/esm/src/utils/priceTickConversions.d.ts +20 -0
  129. package/dist/esm/src/utils/priceTickConversions.js +49 -0
  130. package/dist/esm/src/utils/priceTickConversions.js.map +1 -0
  131. package/dist/esm/src/utils/sortsBefore.d.ts +2 -0
  132. package/dist/esm/src/utils/sortsBefore.js +8 -0
  133. package/dist/esm/src/utils/sortsBefore.js.map +1 -0
  134. package/dist/esm/src/utils/v4BaseActionsParser.d.ts +49 -0
  135. package/dist/esm/src/utils/v4BaseActionsParser.js +189 -0
  136. package/dist/esm/src/utils/v4BaseActionsParser.js.map +1 -0
  137. package/dist/esm/src/utils/v4Planner.d.ts +71 -0
  138. package/dist/esm/src/utils/v4Planner.js +261 -0
  139. package/dist/esm/src/utils/v4Planner.js.map +1 -0
  140. package/dist/esm/src/utils/v4PositionPlanner.d.ts +13 -0
  141. package/dist/esm/src/utils/v4PositionPlanner.js +57 -0
  142. package/dist/esm/src/utils/v4PositionPlanner.js.map +1 -0
  143. package/dist/types/src/PositionManager.d.ts +170 -0
  144. package/dist/types/src/PositionManager.d.ts.map +1 -0
  145. package/dist/types/src/actionConstants.d.ts +2 -0
  146. package/dist/types/src/actionConstants.d.ts.map +1 -0
  147. package/dist/types/src/entities/index.d.ts +5 -0
  148. package/dist/types/src/entities/index.d.ts.map +1 -0
  149. package/dist/types/src/entities/pool.d.ts +104 -0
  150. package/dist/types/src/entities/pool.d.ts.map +1 -0
  151. package/dist/types/src/entities/position.d.ts +145 -0
  152. package/dist/types/src/entities/position.d.ts.map +1 -0
  153. package/dist/types/src/entities/route.d.ts +29 -0
  154. package/dist/types/src/entities/route.d.ts.map +1 -0
  155. package/dist/types/src/entities/trade.d.ts +221 -0
  156. package/dist/types/src/entities/trade.d.ts.map +1 -0
  157. package/dist/types/src/index.d.ts +5 -0
  158. package/dist/types/src/index.d.ts.map +1 -0
  159. package/dist/types/src/internalConstants.d.ts +47 -0
  160. package/dist/types/src/internalConstants.d.ts.map +1 -0
  161. package/dist/types/src/multicall.d.ts +11 -0
  162. package/dist/types/src/multicall.d.ts.map +1 -0
  163. package/dist/types/src/tokenize.d.ts +18 -0
  164. package/dist/types/src/tokenize.d.ts.map +1 -0
  165. package/dist/types/src/utils/calldata.d.ts +21 -0
  166. package/dist/types/src/utils/calldata.d.ts.map +1 -0
  167. package/dist/types/src/utils/currencyMap.d.ts +3 -0
  168. package/dist/types/src/utils/currencyMap.d.ts.map +1 -0
  169. package/dist/types/src/utils/encodeRouteToPath.d.ts +11 -0
  170. package/dist/types/src/utils/encodeRouteToPath.d.ts.map +1 -0
  171. package/dist/types/src/utils/hook.d.ts +46 -0
  172. package/dist/types/src/utils/hook.d.ts.map +1 -0
  173. package/dist/types/src/utils/index.d.ts +12 -0
  174. package/dist/types/src/utils/index.d.ts.map +1 -0
  175. package/dist/types/src/utils/pathCurrency.d.ts +5 -0
  176. package/dist/types/src/utils/pathCurrency.d.ts.map +1 -0
  177. package/dist/types/src/utils/positionManagerAbi.d.ts +103 -0
  178. package/dist/types/src/utils/positionManagerAbi.d.ts.map +1 -0
  179. package/dist/types/src/utils/priceTickConversions.d.ts +21 -0
  180. package/dist/types/src/utils/priceTickConversions.d.ts.map +1 -0
  181. package/dist/types/src/utils/sortsBefore.d.ts +3 -0
  182. package/dist/types/src/utils/sortsBefore.d.ts.map +1 -0
  183. package/dist/types/src/utils/v4BaseActionsParser.d.ts +50 -0
  184. package/dist/types/src/utils/v4BaseActionsParser.d.ts.map +1 -0
  185. package/dist/types/src/utils/v4Planner.d.ts +72 -0
  186. package/dist/types/src/utils/v4Planner.d.ts.map +1 -0
  187. package/dist/types/src/utils/v4PositionPlanner.d.ts +14 -0
  188. package/dist/types/src/utils/v4PositionPlanner.d.ts.map +1 -0
  189. package/package.json +28 -46
  190. package/dist/index.js +0 -8
  191. package/dist/tokenizeAddresses.d.ts +0 -25
  192. package/dist/v4-sdk.cjs.development.js +0 -3633
  193. package/dist/v4-sdk.cjs.development.js.map +0 -1
  194. package/dist/v4-sdk.cjs.production.min.js +0 -2
  195. package/dist/v4-sdk.cjs.production.min.js.map +0 -1
  196. package/dist/v4-sdk.esm.js +0 -3597
  197. package/dist/v4-sdk.esm.js.map +0 -1
@@ -0,0 +1,237 @@
1
+ import { validateAndParseAddress } from '@kittycorn-labs/sdk-core';
2
+ import JSBI from 'jsbi';
3
+ import { Position } from './entities/position.js';
4
+ import { toHex } from './utils/calldata.js';
5
+ import { MSG_SENDER } from './actionConstants.js';
6
+ import { Interface } from '@ethersproject/abi';
7
+ import { Multicall } from './multicall.js';
8
+ import invariant from 'tiny-invariant';
9
+ import { EMPTY_BYTES, CANNOT_BURN, NATIVE_NOT_SET, NO_SQRT_PRICE, ONE, OPEN_DELTA, PositionFunctions, ZERO, ZERO_LIQUIDITY, } from './internalConstants.js';
10
+ import { V4PositionPlanner } from './utils/index.js';
11
+ import { positionManagerAbi } from './utils/positionManagerAbi.js';
12
+ const NFT_PERMIT_TYPES = {
13
+ Permit: [
14
+ { name: 'spender', type: 'address' },
15
+ { name: 'tokenId', type: 'uint256' },
16
+ { name: 'nonce', type: 'uint256' },
17
+ { name: 'deadline', type: 'uint256' },
18
+ ],
19
+ };
20
+ // type guard
21
+ function isMint(options) {
22
+ return Object.keys(options).some((k) => k === 'recipient');
23
+ }
24
+ function shouldCreatePool(options) {
25
+ if (options.createPool) {
26
+ invariant(options.sqrtPriceX96 !== undefined, NO_SQRT_PRICE);
27
+ return true;
28
+ }
29
+ return false;
30
+ }
31
+ export class V4PositionManager {
32
+ /**
33
+ * Cannot be constructed.
34
+ */
35
+ constructor() { }
36
+ /**
37
+ * Public methods to encode method parameters for different actions on the PositionManager contract
38
+ */
39
+ static createCallParameters(poolKey, sqrtPriceX96) {
40
+ return {
41
+ calldata: this.encodeInitializePool(poolKey, sqrtPriceX96),
42
+ value: toHex(0),
43
+ };
44
+ }
45
+ static addCallParameters(position, options) {
46
+ /**
47
+ * Cases:
48
+ * - if pool does not exist yet, encode initializePool
49
+ * then,
50
+ * - if is mint, encode MINT_POSITION. If migrating, encode a SETTLE and SWEEP for both currencies. Else, encode a SETTLE_PAIR. If on a NATIVE pool, encode a SWEEP.
51
+ * - else, encode INCREASE_LIQUIDITY and CLOSE_CURRENCY for each token (handles accrued fees). If on a NATIVE pool, encode a SWEEP.
52
+ */
53
+ invariant(JSBI.greaterThan(position.liquidity, ZERO), ZERO_LIQUIDITY);
54
+ const calldataList = [];
55
+ const planner = new V4PositionPlanner();
56
+ // Encode initialize pool.
57
+ if (isMint(options) && shouldCreatePool(options)) {
58
+ // No planner used here because initializePool is not supported as an Action
59
+ calldataList.push(V4PositionManager.encodeInitializePool(position.pool.poolKey, options.sqrtPriceX96));
60
+ }
61
+ // position.pool.currency0 is native if and only if options.useNative is set
62
+ invariant(position.pool.currency0 === options.useNative ||
63
+ (!position.pool.currency0.isNative && options.useNative === undefined), NATIVE_NOT_SET);
64
+ // adjust for slippage
65
+ const maximumAmounts = position.mintAmountsWithSlippage(options.slippageTolerance);
66
+ const amount0Max = toHex(maximumAmounts.amount0);
67
+ const amount1Max = toHex(maximumAmounts.amount1);
68
+ // We use permit2 to approve tokens to the position manager
69
+ if (options.batchPermit) {
70
+ calldataList.push(V4PositionManager.encodePermitBatch(options.batchPermit.owner, options.batchPermit.permitBatch, options.batchPermit.signature));
71
+ }
72
+ // mint
73
+ if (isMint(options)) {
74
+ const recipient = validateAndParseAddress(options.recipient);
75
+ planner.addMint(position.pool, position.tickLower, position.tickUpper, position.liquidity, amount0Max, amount1Max, recipient, options.hookData);
76
+ }
77
+ else {
78
+ // increase
79
+ planner.addIncrease(options.tokenId, position.liquidity, amount0Max, amount1Max, options.hookData);
80
+ }
81
+ let value = toHex(0);
82
+ // If migrating, we need to settle and sweep both currencies individually
83
+ if (isMint(options) && options.migrate) {
84
+ if (options.useNative) {
85
+ // unwrap the exact amount needed to send to the pool manager
86
+ planner.addUnwrap(OPEN_DELTA);
87
+ }
88
+ // payer is v4 position manager
89
+ planner.addSettle(position.pool.currency0, false);
90
+ planner.addSettle(position.pool.currency1, false);
91
+ // sweep any leftover wrapped native that was not unwrapped
92
+ // recipient will be same as the v4 lp token recipient
93
+ planner.addSweep(options.useNative ? position.pool.currency0.wrapped : position.pool.currency0, options.recipient);
94
+ planner.addSweep(position.pool.currency1, options.recipient);
95
+ }
96
+ else {
97
+ if (isMint(options)) {
98
+ // Mint: the user can never be owed a token when minting (delta is always >= 0), so SETTLE_PAIR is safe
99
+ planner.addSettlePair(position.pool.currency0, position.pool.currency1);
100
+ }
101
+ else {
102
+ // Increase: use CLOSE_CURRENCY instead of SETTLE_PAIR because accrued fees on
103
+ // existing positions can flip the delta positive on one side (e.g. single-sided
104
+ // positions with fees), causing SETTLE_PAIR to revert. CLOSE_CURRENCY handles
105
+ // both directions — settles if the user owes, takes if the user is owed.
106
+ planner.addCloseCurrency(position.pool.currency0);
107
+ planner.addCloseCurrency(position.pool.currency1);
108
+ }
109
+ if (options.useNative) {
110
+ // Any sweeping must happen after the settling.
111
+ // native currency will always be currency0 in v4
112
+ value = toHex(amount0Max);
113
+ planner.addSweep(position.pool.currency0, MSG_SENDER);
114
+ }
115
+ }
116
+ calldataList.push(V4PositionManager.encodeModifyLiquidities(planner.finalize(), options.deadline));
117
+ return {
118
+ calldata: Multicall.encodeMulticall(calldataList),
119
+ value,
120
+ };
121
+ }
122
+ /**
123
+ * Produces the calldata for completely or partially exiting a position
124
+ * @param position The position to exit
125
+ * @param options Additional information necessary for generating the calldata
126
+ * @returns The call parameters
127
+ */
128
+ static removeCallParameters(position, options) {
129
+ var _a;
130
+ /**
131
+ * cases:
132
+ * - if liquidityPercentage is 100%, encode BURN_POSITION and then TAKE_PAIR
133
+ * - else, encode DECREASE_LIQUIDITY and then TAKE_PAIR
134
+ */
135
+ const calldataList = [];
136
+ const planner = new V4PositionPlanner();
137
+ const tokenId = toHex(options.tokenId);
138
+ if (options.burnToken) {
139
+ // if burnToken is true, the specified liquidity percentage must be 100%
140
+ invariant(options.liquidityPercentage.equalTo(ONE), CANNOT_BURN);
141
+ // if there is a permit, encode the ERC721Permit permit call
142
+ if (options.permit) {
143
+ calldataList.push(V4PositionManager.encodeERC721Permit(options.permit.spender, options.permit.tokenId, options.permit.deadline, options.permit.nonce, options.permit.signature));
144
+ }
145
+ // slippage-adjusted amounts derived from current position liquidity
146
+ const { amount0: amount0Min, amount1: amount1Min } = position.burnAmountsWithSlippage(options.slippageTolerance);
147
+ planner.addBurn(tokenId, amount0Min, amount1Min, options.hookData);
148
+ }
149
+ else {
150
+ // construct a partial position with a percentage of liquidity
151
+ const partialPosition = new Position({
152
+ pool: position.pool,
153
+ liquidity: options.liquidityPercentage.multiply(position.liquidity).quotient,
154
+ tickLower: position.tickLower,
155
+ tickUpper: position.tickUpper,
156
+ });
157
+ // If the partial position has liquidity=0, this is a collect call and collectCallParameters should be used
158
+ invariant(JSBI.greaterThan(partialPosition.liquidity, ZERO), ZERO_LIQUIDITY);
159
+ // slippage-adjusted underlying amounts
160
+ const { amount0: amount0Min, amount1: amount1Min } = partialPosition.burnAmountsWithSlippage(options.slippageTolerance);
161
+ planner.addDecrease(tokenId, partialPosition.liquidity.toString(), amount0Min.toString(), amount1Min.toString(), (_a = options.hookData) !== null && _a !== void 0 ? _a : EMPTY_BYTES);
162
+ }
163
+ planner.addTakePair(position.pool.currency0, position.pool.currency1, MSG_SENDER);
164
+ calldataList.push(V4PositionManager.encodeModifyLiquidities(planner.finalize(), options.deadline));
165
+ return {
166
+ calldata: Multicall.encodeMulticall(calldataList),
167
+ value: toHex(0),
168
+ };
169
+ }
170
+ /**
171
+ * Produces the calldata for collecting fees from a position
172
+ * @param position The position to collect fees from
173
+ * @param options Additional information necessary for generating the calldata
174
+ * @returns The call parameters
175
+ */
176
+ static collectCallParameters(position, options) {
177
+ const calldataList = [];
178
+ const planner = new V4PositionPlanner();
179
+ const tokenId = toHex(options.tokenId);
180
+ const recipient = validateAndParseAddress(options.recipient);
181
+ /**
182
+ * To collect fees in V4, we need to:
183
+ * - encode a decrease liquidity by 0
184
+ * - and encode a TAKE_PAIR
185
+ */
186
+ planner.addDecrease(tokenId, '0', '0', '0', options.hookData);
187
+ planner.addTakePair(position.pool.currency0, position.pool.currency1, recipient);
188
+ calldataList.push(V4PositionManager.encodeModifyLiquidities(planner.finalize(), options.deadline));
189
+ return {
190
+ calldata: Multicall.encodeMulticall(calldataList),
191
+ value: toHex(0),
192
+ };
193
+ }
194
+ // Initialize a pool
195
+ static encodeInitializePool(poolKey, sqrtPriceX96) {
196
+ return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.INITIALIZE_POOL, [
197
+ poolKey,
198
+ sqrtPriceX96.toString(),
199
+ ]);
200
+ }
201
+ // Encode a modify liquidities call
202
+ static encodeModifyLiquidities(unlockData, deadline) {
203
+ return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.MODIFY_LIQUIDITIES, [unlockData, deadline]);
204
+ }
205
+ // Encode a permit batch call
206
+ static encodePermitBatch(owner, permitBatch, signature) {
207
+ return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.PERMIT_BATCH, [
208
+ owner,
209
+ permitBatch,
210
+ signature,
211
+ ]);
212
+ }
213
+ // Encode a ERC721Permit permit call
214
+ static encodeERC721Permit(spender, tokenId, deadline, nonce, signature) {
215
+ return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.ERC721PERMIT_PERMIT, [
216
+ spender,
217
+ tokenId,
218
+ deadline,
219
+ nonce,
220
+ signature,
221
+ ]);
222
+ }
223
+ // Prepare the params for an EIP712 signTypedData request
224
+ static getPermitData(permit, positionManagerAddress, chainId) {
225
+ return {
226
+ domain: {
227
+ name: 'Uniswap V4 Positions NFT',
228
+ chainId,
229
+ verifyingContract: positionManagerAddress,
230
+ },
231
+ types: NFT_PERMIT_TYPES,
232
+ values: permit,
233
+ };
234
+ }
235
+ }
236
+ V4PositionManager.INTERFACE = new Interface(positionManagerAbi);
237
+ //# sourceMappingURL=PositionManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PositionManager.js","sourceRoot":"","sources":["../../../src/PositionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,uBAAuB,EAAkB,MAAM,0BAA0B,CAAA;AAEtG,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAA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EAAE,sBAA8B,EAAE,OAAe;QAClG,OAAO;YACL,MAAM,EAAE;gBACN,IAAI,EAAE,0BAA0B;gBAChC,OAAO;gBACP,iBAAiB,EAAE,sBAAsB;aAC1C;YACD,KAAK,EAAE,gBAAgB;YACvB,MAAM,EAAE,MAAM;SACf,CAAA;IACH,CAAC;;AAlRa,2BAAS,GAAc,IAAI,SAAS,CAAC,kBAAkB,CAAC,CAAA"}
@@ -0,0 +1,23 @@
1
+ {
2
+ "abi": [
3
+ {
4
+ "inputs": [
5
+ {
6
+ "internalType": "bytes[]",
7
+ "name": "data",
8
+ "type": "bytes[]"
9
+ }
10
+ ],
11
+ "name": "multicall",
12
+ "outputs": [
13
+ {
14
+ "internalType": "bytes[]",
15
+ "name": "results",
16
+ "type": "bytes[]"
17
+ }
18
+ ],
19
+ "stateMutability": "payable",
20
+ "type": "function"
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1 @@
1
+ export declare const MSG_SENDER = "0x0000000000000000000000000000000000000001";
@@ -0,0 +1,3 @@
1
+ // Shared Action Constants used in the v4 Router and v4 position manager
2
+ export const MSG_SENDER = '0x0000000000000000000000000000000000000001';
3
+ //# sourceMappingURL=actionConstants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionConstants.js","sourceRoot":"","sources":["../../../src/actionConstants.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,CAAC,MAAM,UAAU,GAAG,4CAA4C,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './pool';
2
+ export * from './route';
3
+ export * from './trade';
4
+ export * from './position';
@@ -0,0 +1,5 @@
1
+ export * from './pool.js';
2
+ export * from './route.js';
3
+ export * from './trade.js';
4
+ export * from './position.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA"}
@@ -0,0 +1,103 @@
1
+ import { BigintIsh, Currency, CurrencyAmount, Price } from '@kittycorn-labs/sdk-core';
2
+ import { Tick, TickConstructorArgs, TickDataProvider } from '@kittycorn-labs/v3-sdk';
3
+ import JSBI from 'jsbi';
4
+ export declare const DYNAMIC_FEE_FLAG = 8388608;
5
+ export type PoolKey = {
6
+ currency0: string;
7
+ currency1: string;
8
+ fee: number;
9
+ tickSpacing: number;
10
+ hooks: string;
11
+ };
12
+ /**
13
+ * Represents a V4 pool
14
+ */
15
+ export declare class Pool {
16
+ readonly currency0: Currency;
17
+ readonly currency1: Currency;
18
+ readonly fee: number;
19
+ readonly tickSpacing: number;
20
+ readonly sqrtRatioX96: JSBI;
21
+ readonly hooks: string;
22
+ readonly liquidity: JSBI;
23
+ readonly tickCurrent: number;
24
+ readonly tickDataProvider: TickDataProvider;
25
+ readonly poolKey: PoolKey;
26
+ readonly poolId: string;
27
+ private _currency0Price?;
28
+ private _currency1Price?;
29
+ static getPoolKey(currencyA: Currency, currencyB: Currency, fee: number, tickSpacing: number, hooks: string): PoolKey;
30
+ static getPoolId(currencyA: Currency, currencyB: Currency, fee: number, tickSpacing: number, hooks: string): string;
31
+ /**
32
+ * Construct a pool
33
+ * @param currencyA One of the currencys in the pool
34
+ * @param currencyB The other currency in the pool
35
+ * @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
36
+ * @param tickSpacing The tickSpacing of the pool
37
+ * @param hooks The address of the hook contract
38
+ * @param sqrtRatioX96 The sqrt of the current ratio of amounts of currency1 to currency0
39
+ * @param liquidity The current value of in range liquidity
40
+ * @param tickCurrent The current tick of the pool
41
+ */
42
+ constructor(currencyA: Currency, currencyB: Currency, fee: number, tickSpacing: number, hooks: string, sqrtRatioX96: BigintIsh, liquidity: BigintIsh, tickCurrent: number, ticks?: TickDataProvider | (Tick | TickConstructorArgs)[]);
43
+ /** backwards compatibility with v2/3 sdks */
44
+ get token0(): Currency;
45
+ get token1(): Currency;
46
+ /**
47
+ * Returns true if the currency is either currency0 or currency1
48
+ * @param currency The currency to check
49
+ * @returns True if currency is either currency0 or currency1
50
+ */
51
+ involvesCurrency(currency: Currency): boolean;
52
+ /** backwards compatibility with v2/3 sdks */
53
+ involvesToken(currency: Currency): boolean;
54
+ /**
55
+ * v4-only involvesToken convenience method, used for mixed route ETH <-> WETH connection only
56
+ * @param currency
57
+ */
58
+ v4InvolvesToken(currency: Currency): boolean;
59
+ /**
60
+ * Returns the current mid price of the pool in terms of currency0, i.e. the ratio of currency1 over currency0
61
+ */
62
+ get currency0Price(): Price<Currency, Currency>;
63
+ /** backwards compatibility with v2/3 sdks */
64
+ get token0Price(): Price<Currency, Currency>;
65
+ /**
66
+ * Returns the current mid price of the pool in terms of currency1, i.e. the ratio of currency0 over currency1
67
+ */
68
+ get currency1Price(): Price<Currency, Currency>;
69
+ /** backwards compatibility with v2/3 sdks */
70
+ get token1Price(): Price<Currency, Currency>;
71
+ /**
72
+ * Return the price of the given currency in terms of the other currency in the pool.
73
+ * @param currency The currency to return price of
74
+ * @returns The price of the given currency, in terms of the other.
75
+ */
76
+ priceOf(currency: Currency): Price<Currency, Currency>;
77
+ /**
78
+ * Returns the chain ID of the currencies in the pool.
79
+ */
80
+ get chainId(): number;
81
+ /** Works only for vanilla hookless v3 pools, otherwise throws an error */
82
+ getOutputAmount(inputAmount: CurrencyAmount<Currency>, sqrtPriceLimitX96?: JSBI): Promise<[CurrencyAmount<Currency>, Pool]>;
83
+ /**
84
+ * Given a desired output amount of a currency, return the computed input amount and a pool with state updated after the trade
85
+ * Works only for vanilla hookless v3 pools, otherwise throws an error
86
+ * @param outputAmount the output amount for which to quote the input amount
87
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
88
+ * @returns The input amount and the pool with updated state
89
+ */
90
+ getInputAmount(outputAmount: CurrencyAmount<Currency>, sqrtPriceLimitX96?: JSBI): Promise<[CurrencyAmount<Currency>, Pool]>;
91
+ /**
92
+ * Executes a swap
93
+ * @param zeroForOne Whether the amount in is token0 or token1
94
+ * @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
95
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
96
+ * @returns amountCalculated
97
+ * @returns sqrtRatioX96
98
+ * @returns liquidity
99
+ * @returns tickCurrent
100
+ */
101
+ private swap;
102
+ private hookImpactsSwap;
103
+ }
@@ -0,0 +1,191 @@
1
+ import invariant from 'tiny-invariant';
2
+ import { keccak256 } from '@ethersproject/solidity';
3
+ import { CurrencyAmount, Price } from '@kittycorn-labs/sdk-core';
4
+ import { v3Swap, NoTickDataProvider, TickListDataProvider, TickMath, } from '@kittycorn-labs/v3-sdk';
5
+ import { defaultAbiCoder } from '@ethersproject/abi';
6
+ import { isAddress } from '@ethersproject/address';
7
+ import { sortsBefore } from '../utils/sortsBefore.js';
8
+ import { Hook } from '../utils/hook.js';
9
+ import { ADDRESS_ZERO, NEGATIVE_ONE, Q192 } from '../internalConstants.js';
10
+ import JSBI from 'jsbi';
11
+ export const DYNAMIC_FEE_FLAG = 0x800000;
12
+ const NO_TICK_DATA_PROVIDER_DEFAULT = new NoTickDataProvider();
13
+ /**
14
+ * Represents a V4 pool
15
+ */
16
+ export class Pool {
17
+ static getPoolKey(currencyA, currencyB, fee, tickSpacing, hooks) {
18
+ invariant(isAddress(hooks), 'Invalid hook address');
19
+ const [currency0, currency1] = sortsBefore(currencyA, currencyB) ? [currencyA, currencyB] : [currencyB, currencyA];
20
+ const currency0Addr = currency0.isNative ? ADDRESS_ZERO : currency0.wrapped.address;
21
+ const currency1Addr = currency1.isNative ? ADDRESS_ZERO : currency1.wrapped.address;
22
+ return {
23
+ currency0: currency0Addr,
24
+ currency1: currency1Addr,
25
+ fee,
26
+ tickSpacing,
27
+ hooks,
28
+ };
29
+ }
30
+ static getPoolId(currencyA, currencyB, fee, tickSpacing, hooks) {
31
+ const [currency0, currency1] = sortsBefore(currencyA, currencyB) ? [currencyA, currencyB] : [currencyB, currencyA];
32
+ const currency0Addr = currency0.isNative ? ADDRESS_ZERO : currency0.wrapped.address;
33
+ const currency1Addr = currency1.isNative ? ADDRESS_ZERO : currency1.wrapped.address;
34
+ return keccak256(['bytes'], [
35
+ defaultAbiCoder.encode(['address', 'address', 'uint24', 'int24', 'address'], [currency0Addr, currency1Addr, fee, tickSpacing, hooks]),
36
+ ]);
37
+ }
38
+ /**
39
+ * Construct a pool
40
+ * @param currencyA One of the currencys in the pool
41
+ * @param currencyB The other currency in the pool
42
+ * @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
43
+ * @param tickSpacing The tickSpacing of the pool
44
+ * @param hooks The address of the hook contract
45
+ * @param sqrtRatioX96 The sqrt of the current ratio of amounts of currency1 to currency0
46
+ * @param liquidity The current value of in range liquidity
47
+ * @param tickCurrent The current tick of the pool
48
+ */
49
+ constructor(currencyA, currencyB, fee, tickSpacing, hooks, sqrtRatioX96, liquidity, tickCurrent, ticks = NO_TICK_DATA_PROVIDER_DEFAULT) {
50
+ invariant(isAddress(hooks), 'Invalid hook address');
51
+ invariant(Number.isInteger(fee) && (fee === DYNAMIC_FEE_FLAG || fee < 1000000), 'FEE');
52
+ if (fee === DYNAMIC_FEE_FLAG) {
53
+ invariant(Number(hooks) > 0, 'Dynamic fee pool requires a hook');
54
+ }
55
+ const tickCurrentSqrtRatioX96 = TickMath.getSqrtRatioAtTick(tickCurrent);
56
+ const nextTickSqrtRatioX96 = TickMath.getSqrtRatioAtTick(tickCurrent + 1);
57
+ invariant(JSBI.greaterThanOrEqual(JSBI.BigInt(sqrtRatioX96), tickCurrentSqrtRatioX96) &&
58
+ JSBI.lessThanOrEqual(JSBI.BigInt(sqrtRatioX96), nextTickSqrtRatioX96), 'PRICE_BOUNDS');
59
+ [this.currency0, this.currency1] = sortsBefore(currencyA, currencyB)
60
+ ? [currencyA, currencyB]
61
+ : [currencyB, currencyA];
62
+ this.fee = fee;
63
+ this.sqrtRatioX96 = JSBI.BigInt(sqrtRatioX96);
64
+ this.tickSpacing = tickSpacing;
65
+ this.hooks = hooks;
66
+ this.liquidity = JSBI.BigInt(liquidity);
67
+ this.tickCurrent = tickCurrent;
68
+ this.tickDataProvider = Array.isArray(ticks) ? new TickListDataProvider(ticks, tickSpacing) : ticks;
69
+ this.poolKey = Pool.getPoolKey(this.currency0, this.currency1, this.fee, this.tickSpacing, this.hooks);
70
+ this.poolId = Pool.getPoolId(this.currency0, this.currency1, this.fee, this.tickSpacing, this.hooks);
71
+ }
72
+ /** backwards compatibility with v2/3 sdks */
73
+ get token0() {
74
+ return this.currency0;
75
+ }
76
+ get token1() {
77
+ return this.currency1;
78
+ }
79
+ /**
80
+ * Returns true if the currency is either currency0 or currency1
81
+ * @param currency The currency to check
82
+ * @returns True if currency is either currency0 or currency1
83
+ */
84
+ involvesCurrency(currency) {
85
+ return currency.equals(this.currency0) || currency.equals(this.currency1);
86
+ }
87
+ /** backwards compatibility with v2/3 sdks */
88
+ involvesToken(currency) {
89
+ return this.involvesCurrency(currency);
90
+ }
91
+ /**
92
+ * v4-only involvesToken convenience method, used for mixed route ETH <-> WETH connection only
93
+ * @param currency
94
+ */
95
+ v4InvolvesToken(currency) {
96
+ return (this.involvesCurrency(currency) ||
97
+ currency.wrapped.equals(this.currency0) ||
98
+ currency.wrapped.equals(this.currency1) ||
99
+ currency.wrapped.equals(this.currency0.wrapped) ||
100
+ currency.wrapped.equals(this.currency1.wrapped));
101
+ }
102
+ /**
103
+ * Returns the current mid price of the pool in terms of currency0, i.e. the ratio of currency1 over currency0
104
+ */
105
+ get currency0Price() {
106
+ var _a;
107
+ return ((_a = this._currency0Price) !== null && _a !== void 0 ? _a : (this._currency0Price = new Price(this.currency0, this.currency1, Q192, JSBI.multiply(this.sqrtRatioX96, this.sqrtRatioX96))));
108
+ }
109
+ /** backwards compatibility with v2/3 sdks */
110
+ get token0Price() {
111
+ return this.currency0Price;
112
+ }
113
+ /**
114
+ * Returns the current mid price of the pool in terms of currency1, i.e. the ratio of currency0 over currency1
115
+ */
116
+ get currency1Price() {
117
+ var _a;
118
+ return ((_a = this._currency1Price) !== null && _a !== void 0 ? _a : (this._currency1Price = new Price(this.currency1, this.currency0, JSBI.multiply(this.sqrtRatioX96, this.sqrtRatioX96), Q192)));
119
+ }
120
+ /** backwards compatibility with v2/3 sdks */
121
+ get token1Price() {
122
+ return this.currency1Price;
123
+ }
124
+ /**
125
+ * Return the price of the given currency in terms of the other currency in the pool.
126
+ * @param currency The currency to return price of
127
+ * @returns The price of the given currency, in terms of the other.
128
+ */
129
+ priceOf(currency) {
130
+ invariant(this.involvesCurrency(currency), 'CURRENCY');
131
+ return currency.equals(this.currency0) ? this.currency0Price : this.currency1Price;
132
+ }
133
+ /**
134
+ * Returns the chain ID of the currencies in the pool.
135
+ */
136
+ get chainId() {
137
+ return this.currency0.chainId;
138
+ }
139
+ /** Works only for vanilla hookless v3 pools, otherwise throws an error */
140
+ async getOutputAmount(inputAmount, sqrtPriceLimitX96) {
141
+ invariant(this.involvesCurrency(inputAmount.currency), 'CURRENCY');
142
+ const zeroForOne = inputAmount.currency.equals(this.currency0);
143
+ const { amountCalculated: outputAmount, sqrtRatioX96, liquidity, tickCurrent, } = await this.swap(zeroForOne, inputAmount.quotient, sqrtPriceLimitX96);
144
+ const outputCurrency = zeroForOne ? this.currency1 : this.currency0;
145
+ return [
146
+ CurrencyAmount.fromRawAmount(outputCurrency, JSBI.multiply(outputAmount, NEGATIVE_ONE)),
147
+ new Pool(this.currency0, this.currency1, this.fee, this.tickSpacing, this.hooks, sqrtRatioX96, liquidity, tickCurrent, this.tickDataProvider),
148
+ ];
149
+ }
150
+ /**
151
+ * Given a desired output amount of a currency, return the computed input amount and a pool with state updated after the trade
152
+ * Works only for vanilla hookless v3 pools, otherwise throws an error
153
+ * @param outputAmount the output amount for which to quote the input amount
154
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
155
+ * @returns The input amount and the pool with updated state
156
+ */
157
+ async getInputAmount(outputAmount, sqrtPriceLimitX96) {
158
+ invariant(this.involvesCurrency(outputAmount.currency), 'CURRENCY');
159
+ const zeroForOne = outputAmount.currency.equals(this.currency1);
160
+ const { amountCalculated: inputAmount, sqrtRatioX96, liquidity, tickCurrent, } = await this.swap(zeroForOne, JSBI.multiply(outputAmount.quotient, NEGATIVE_ONE), sqrtPriceLimitX96);
161
+ const inputCurrency = zeroForOne ? this.currency0 : this.currency1;
162
+ return [
163
+ CurrencyAmount.fromRawAmount(inputCurrency, inputAmount),
164
+ new Pool(this.currency0, this.currency1, this.fee, this.tickSpacing, this.hooks, sqrtRatioX96, liquidity, tickCurrent, this.tickDataProvider),
165
+ ];
166
+ }
167
+ /**
168
+ * Executes a swap
169
+ * @param zeroForOne Whether the amount in is token0 or token1
170
+ * @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
171
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
172
+ * @returns amountCalculated
173
+ * @returns sqrtRatioX96
174
+ * @returns liquidity
175
+ * @returns tickCurrent
176
+ */
177
+ async swap(zeroForOne, amountSpecified, sqrtPriceLimitX96) {
178
+ if (!this.hookImpactsSwap()) {
179
+ return v3Swap(JSBI.BigInt(this.fee), this.sqrtRatioX96, this.tickCurrent, this.liquidity, this.tickSpacing, this.tickDataProvider, zeroForOne, amountSpecified, sqrtPriceLimitX96);
180
+ }
181
+ else {
182
+ throw new Error('Unsupported hook');
183
+ }
184
+ }
185
+ hookImpactsSwap() {
186
+ // could use this function to clear certain hooks that may have swap Permissions, but we know they don't interfere
187
+ // in the swap outcome
188
+ return Hook.hasSwapPermissions(this.hooks);
189
+ }
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