@apex_labs/sdk 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Apex SDK
2
2
 
3
- Frontend SDK for Apex CL and Classic pools. It vendors a pinned `@pancakeswap/v3-sdk@3.10.0` snapshot as an Apex-owned fork, then adds Apex fee tiers, Apex CREATE2 address helpers, Classic AMM quoting, mixed CL/Classic path encoding, and exact ABI exports for the Apex contracts.
3
+ SDK for Apex CL and Classic pools. It vendors a pinned `@pancakeswap/v3-sdk@3.10.0` snapshot as an Apex-owned fork, then adds Apex fee tiers, Apex CREATE2 address helpers, Classic AMM quoting, mixed CL/Classic path encoding, and exact ABI exports for the Apex contracts.
4
4
 
5
5
  ## Setup
6
6
 
@@ -43,37 +43,37 @@ export const apex: ApexDeploymentConfig = {
43
43
  };
44
44
  ```
45
45
 
46
- ## Functions frontend should care about
46
+ ## Core exports
47
47
 
48
48
  ```ts
49
49
  import {
50
- ApexFeeAmount,
50
+ CLFeeAmount,
51
51
  APEX_CL_POOL_INIT_CODE_HASH,
52
52
  APEX_CL_TICK_SPACINGS,
53
53
  APEX_CLASSIC_PAIR_INIT_CODE_HASH,
54
- ApexClassicFarm,
55
- ApexCLFarm,
56
- ApexSmartRouter,
57
- ApexVaultPosition,
58
- getApexTickSpacing,
59
- createApexPool,
54
+ ClassicChef,
55
+ CLMasterChef,
56
+ SmartRouter,
57
+ ApexVault,
58
+ getCLTickSpacing,
59
+ createCLPool,
60
60
  computeCLPoolAddress,
61
61
  computeClassicPoolAddress,
62
- quoteApexClassicExactInput,
63
- encodeApexMixedRouteToPath,
64
- encodeApexMixedRouteToPancakeQuoteParams,
65
- decodeApexMixedRoutePath,
66
- parseApexProtocolFeePacked,
67
- apexCLPoolAbi,
68
- apexCLFactoryAbi,
69
- apexCLMasterChefAbi,
70
- apexNonfungiblePositionManagerAbi,
71
- apexSwapRouterAbi,
72
- apexSmartRouterAbi,
73
- apexMixedQuoterAbi,
74
- apexQuoterV2Abi,
75
- apexClassicFactoryAbi,
76
- apexClassicPairAbi,
62
+ quoteClassicExactInput,
63
+ encodeMixedRouteToPath,
64
+ encodeMixedRouteToPancakeQuoteParams,
65
+ decodeMixedRoutePath,
66
+ parseProtocolFeePacked,
67
+ clPoolAbi,
68
+ clFactoryAbi,
69
+ clMasterChefAbi,
70
+ nonfungiblePositionManagerAbi,
71
+ swapRouterAbi,
72
+ smartRouterAbi,
73
+ mixedQuoterAbi,
74
+ quoterV2Abi,
75
+ classicFactoryAbi,
76
+ classicPoolAbi,
77
77
  Pool,
78
78
  Route,
79
79
  Trade,
@@ -93,17 +93,17 @@ const pool = computeCLPoolAddress({
93
93
  config: apex,
94
94
  tokenA,
95
95
  tokenB,
96
- fee: ApexFeeAmount.FEE_0_30,
96
+ fee: CLFeeAmount.FEE_0_30,
97
97
  });
98
98
  ```
99
99
 
100
100
  ### CL pool object
101
101
 
102
102
  ```ts
103
- const pool = createApexPool({
103
+ const pool = createCLPool({
104
104
  tokenA,
105
105
  tokenB,
106
- fee: ApexFeeAmount.FEE_0_30,
106
+ fee: CLFeeAmount.FEE_0_30,
107
107
  sqrtRatioX96,
108
108
  liquidity,
109
109
  tickCurrent,
@@ -111,7 +111,7 @@ const pool = createApexPool({
111
111
  });
112
112
  ```
113
113
 
114
- `createApexPool` returns the forked Pancake `Pool`, with Apex fee tiers installed. Position, trade, route, quoter, swap-router, and NFT-position-manager logic should use the classes re-exported by `@apex_labs/sdk`.
114
+ `createCLPool` returns the forked Pancake `Pool`, with Apex fee tiers installed. Position, trade, route, quoter, swap-router, and NFT-position-manager logic should use the classes re-exported by `@apex_labs/sdk`.
115
115
 
116
116
  ### Periphery ABIs
117
117
 
@@ -119,19 +119,19 @@ Use the exact ABIs exported from compiled Apex contracts:
119
119
 
120
120
  ```ts
121
121
  import {
122
- apexNonfungiblePositionManagerAbi,
123
- apexSwapRouterAbi,
124
- apexQuoterAbi,
125
- apexQuoterV2Abi,
126
- apexSmartRouterAbi,
127
- apexMixedQuoterAbi,
128
- apexTickLensAbi,
129
- apexInterfaceMulticallAbi,
130
- apexCLFactoryAbi,
131
- apexCLMasterChefAbi,
132
- apexCLPoolAbi,
133
- apexClassicFactoryAbi,
134
- apexClassicPairAbi,
122
+ nonfungiblePositionManagerAbi,
123
+ swapRouterAbi,
124
+ quoterAbi,
125
+ quoterV2Abi,
126
+ smartRouterAbi,
127
+ mixedQuoterAbi,
128
+ tickLensAbi,
129
+ interfaceMulticallAbi,
130
+ clFactoryAbi,
131
+ clMasterChefAbi,
132
+ clPoolAbi,
133
+ classicFactoryAbi,
134
+ classicPoolAbi,
135
135
  } from "@apex_labs/sdk";
136
136
  ```
137
137
 
@@ -149,7 +149,7 @@ const stablePair = computeClassicPoolAddress({
149
149
  ### Classic quote
150
150
 
151
151
  ```ts
152
- const amountOut = quoteApexClassicExactInput({
152
+ const amountOut = quoteClassicExactInput({
153
153
  amountIn,
154
154
  tokenIn: tokenA.address,
155
155
  token0,
@@ -165,19 +165,19 @@ const amountOut = quoteApexClassicExactInput({
165
165
 
166
166
  ### Classic farm UX
167
167
 
168
- Use `ApexClassicFarm` for Classic LP staking. Pools are pid-based; read `ClassicChef.pidOf(pair)` from the exported ABI or an indexed farm list, then encode normal stake/claim/exit calls:
168
+ Use `ClassicChef` for Classic LP staking. Pools are pid-based; read `ClassicChef.pidOf(pair)` from the exported ABI or an indexed farm list, then encode normal stake/claim/exit calls:
169
169
 
170
170
  ```ts
171
- const stakeClassic = ApexClassicFarm.depositCallParameters({
171
+ const stakeClassic = ClassicChef.depositCallParameters({
172
172
  pid,
173
173
  amount,
174
174
  });
175
175
 
176
- const claimClassic = ApexClassicFarm.harvestCallParameters({
176
+ const claimClassic = ClassicChef.harvestCallParameters({
177
177
  pid,
178
178
  });
179
179
 
180
- const exitClassic = ApexClassicFarm.withdrawCallParameters({
180
+ const exitClassic = ClassicChef.withdrawCallParameters({
181
181
  pid,
182
182
  amount,
183
183
  });
@@ -186,23 +186,23 @@ const exitClassic = ApexClassicFarm.withdrawCallParameters({
186
186
  ### Mixed CL/Classic path
187
187
 
188
188
  ```ts
189
- const path = encodeApexMixedRouteToPath([
189
+ const path = encodeMixedRouteToPath([
190
190
  {
191
191
  kind: "CL",
192
192
  tokenIn: tokenA.address,
193
193
  tokenOut: tokenB.address,
194
- fee: ApexFeeAmount.FEE_0_30,
194
+ fee: CLFeeAmount.FEE_0_30,
195
195
  },
196
196
  { kind: "CLASSIC_STABLE", tokenIn: tokenB.address, tokenOut: tokenC.address },
197
197
  ]);
198
198
  ```
199
199
 
200
200
  Quote that path through `MixedQuoter.quoteExactInput(path, amountIn)`, then execute it with
201
- `ApexSmartRouter`. The high-level helpers follow Pancake SmartRouter’s safety pattern:
201
+ `SmartRouter`. The high-level helpers follow Pancake SmartRouter’s safety pattern:
202
202
  they encode the swap, then wrap it in `SmartRouter.multicall(deadlineOrPreviousBlockhash, data)`.
203
203
 
204
204
  ```ts
205
- const swap = ApexSmartRouter.mixedExactInputCallParameters(
205
+ const swap = SmartRouter.mixedExactInputCallParameters(
206
206
  { hops, recipient: account, amountIn, amountOutMinimum },
207
207
  { deadlineOrPreviousBlockhash: deadline },
208
208
  );
@@ -211,10 +211,10 @@ const swap = ApexSmartRouter.mixedExactInputCallParameters(
211
211
  If you fork Pancake SmartRouter’s mixed quote provider, use Pancake-style quote params:
212
212
 
213
213
  ```ts
214
- const { path, flags } = encodeApexMixedRouteToPancakeQuoteParams(hops);
214
+ const { path, flags } = encodeMixedRouteToPancakeQuoteParams(hops);
215
215
  const quote = await publicClient.readContract({
216
216
  address: apex.mixedQuoter,
217
- abi: apexMixedQuoterAbi,
217
+ abi: mixedQuoterAbi,
218
218
  functionName: "quoteExactInput",
219
219
  args: [path, flags, amountIn],
220
220
  });
@@ -224,38 +224,40 @@ For routes that Pancake SmartRouter partitions by protocol:
224
224
 
225
225
  ```ts
226
226
  // Classic volatile section
227
- ApexSmartRouter.classicExactInputCallParameters(
227
+ SmartRouter.classicExactInputCallParameters(
228
228
  { amountIn, amountOutMin, path, recipient },
229
229
  { deadlineOrPreviousBlockhash: deadline },
230
230
  );
231
231
 
232
232
  // Classic stable section
233
- ApexSmartRouter.stableExactInputCallParameters(
233
+ SmartRouter.stableExactInputCallParameters(
234
234
  { amountIn, amountOutMin, path, flags, recipient },
235
235
  { deadlineOrPreviousBlockhash: deadline },
236
236
  );
237
237
 
238
238
  // CL section
239
- ApexSmartRouter.exactInputCallParameters(
239
+ SmartRouter.exactInputCallParameters(
240
240
  { path, recipient, amountIn, amountOutMinimum },
241
241
  { deadlineOrPreviousBlockhash: deadline },
242
242
  );
243
243
  ```
244
244
 
245
- Use the raw `encode*` helpers only when deliberately assembling a custom multicall. User-facing swaps should use `*CallParameters`, or `ApexSmartRouter.swapCallParameters(rawCalls, options)` for custom batches. These require a deadline or previous blockhash and support cleanup calls such as `refundETH`, `sweepToken`, and `unwrapWETH9`.
245
+ Use the raw `encode*` helpers only when deliberately assembling a custom multicall. User-facing swaps should use `*CallParameters`, or `SmartRouter.swapCallParameters(rawCalls, options)` for custom batches. These require a deadline or previous blockhash.
246
+
247
+ When `value` is nonzero, `SmartRouter` call-parameter helpers append `refundETH()` automatically. Token sweeps and WETH unwraps require explicit cleanup entries because the SDK cannot infer the intended token, recipient, or minimum amount for every route.
246
248
 
247
249
  The mixed periphery is exact-input only. Use the CL-only `SwapRouter`/`QuoterV2` for CL exact-output routes.
248
250
 
249
251
  ### CL farm UX
250
252
 
251
- Use `ApexCLFarm` for staked CL positions. It encodes the Apex-safe paths instead of making the frontend assemble Chef calls by hand.
253
+ Use `CLMasterChef` for staked CL positions. It encodes the supported paths without requiring applications to assemble Chef calls directly.
252
254
 
253
255
  ```ts
254
- const { calldata, value } = ApexCLFarm.mintAndStakeCallParameters(
256
+ const { calldata, value } = CLMasterChef.mintAndStakeCallParameters(
255
257
  {
256
258
  token0: tokenA.address,
257
259
  token1: tokenB.address,
258
- fee: ApexFeeAmount.FEE_0_30,
260
+ fee: CLFeeAmount.FEE_0_30,
259
261
  tickLower,
260
262
  tickUpper,
261
263
  amount0Desired,
@@ -272,19 +274,19 @@ const { calldata, value } = ApexCLFarm.mintAndStakeCallParameters(
272
274
  );
273
275
  ```
274
276
 
275
- `mintAndStakeCallParameters` takes `account` and encodes it as the staked NFT owner. It rejects the Chef and NFP manager as owners so frontend callers cannot strand positions in protocol contracts.
277
+ `mintAndStakeCallParameters` takes `account` and encodes it as the staked NFT owner. It rejects the Chef and NFP manager as owners so callers cannot strand positions in protocol contracts.
276
278
 
277
279
  When minting with native ETH, pass `value` in the options object. The SDK appends `refundETH()` in the same NFP multicall only when value is nonzero.
278
280
 
279
281
  For fee collection on staked NFTs, prefer `collectCallParameters` or `decreaseAndCollectCallParameters`:
280
282
 
281
283
  ```ts
282
- const collect = ApexCLFarm.collectCallParameters({
284
+ const collect = CLMasterChef.collectCallParameters({
283
285
  tokenId,
284
286
  recipient: account,
285
287
  });
286
288
 
287
- const exitPart = ApexCLFarm.decreaseAndCollectCallParameters(
289
+ const exitPart = CLMasterChef.decreaseAndCollectCallParameters(
288
290
  { tokenId, liquidity, amount0Min, amount1Min, deadline },
289
291
  { tokenId, recipient: account },
290
292
  );
@@ -295,7 +297,7 @@ These helpers call `CLMasterChef.multicall(...)` and use `collectTo` with the in
295
297
  For a full exit, use `closeAndBurnCallParameters`:
296
298
 
297
299
  ```ts
298
- const close = ApexCLFarm.closeAndBurnCallParameters(
300
+ const close = CLMasterChef.closeAndBurnCallParameters(
299
301
  { tokenId, liquidity, amount0Min, amount1Min, deadline },
300
302
  { tokenId, recipient: account },
301
303
  );
@@ -303,17 +305,17 @@ const close = ApexCLFarm.closeAndBurnCallParameters(
303
305
 
304
306
  This encodes `harvest -> decreaseLiquidity -> collectTo -> burn`. The harvest happens before liquidity is removed, so it is safe even when rewards are zero and keeps `burn` compatible with Pancake-style strict empty-position semantics.
305
307
 
306
- ### Apex Vault UX
308
+ ### ApexVault UX
307
309
 
308
- Use `ApexVaultPosition` for user-facing VeApexToken vault actions. Users choose reward-token percentages and a compound percentage. Compound is not user-claimable APEX; the user config only selects the compound bucket, and the protocol operator later calls the controller/vault compound functions.
310
+ Use `ApexVault` for user-facing VeApexToken actions. Users choose reward-token percentages and a compound percentage. Compound is not user-claimable APEX; the user config selects the compound bucket, and the protocol operator later calls the controller and ApexVault compound functions.
309
311
 
310
312
  ```ts
311
- const approveVault = ApexVaultPosition.encodeVeApexTokenApprove({
313
+ const approveVault = ApexVault.encodeVeApexTokenApprove({
312
314
  tokenId,
313
315
  spender: apexVault,
314
316
  });
315
317
 
316
- const stake = ApexVaultPosition.stakeCallParameters(tokenId, {
318
+ const stake = ApexVault.stakeCallParameters(tokenId, {
317
319
  rewardConfigs: [
318
320
  { rewardToken: weth, bps: 5_000 },
319
321
  { rewardToken: usdc, bps: 2_000 },
@@ -327,28 +329,28 @@ The helper rejects configs that do not sum to exactly `10_000` bps, repeat a rew
327
329
  For an existing staked veNFT:
328
330
 
329
331
  ```ts
330
- const updateConfig = ApexVaultPosition.setUserConfigCallParameters(tokenId, {
332
+ const updateConfig = ApexVault.setUserConfigCallParameters(tokenId, {
331
333
  rewardConfigs: [{ rewardToken: weth, bps: 7_000 }],
332
334
  compoundBps: 3_000,
333
335
  });
334
336
 
335
- const claim = ApexVaultPosition.claimCallParameters({
337
+ const claim = ApexVault.claimCallParameters({
336
338
  tokenId,
337
339
  rewardTokens: [weth, usdc],
338
340
  });
339
341
 
340
- const extend = ApexVaultPosition.extendLockCallParameters({
342
+ const extend = ApexVault.extendLockCallParameters({
341
343
  tokenId,
342
344
  lockDuration: 26n * 7n * 86_400n,
343
345
  });
344
346
 
345
- const increase = ApexVaultPosition.increaseAmountCallParameters({
347
+ const increase = ApexVault.increaseAmountCallParameters({
346
348
  tokenId,
347
349
  amount,
348
350
  });
349
351
  ```
350
352
 
351
- The vault is custodial while staked. For staked veNFTs, route amount increases through `ApexVaultPosition.increaseAmountCallParameters(...)`, not raw `VeApexToken.depositFor(...)`, so Vault reward weights are refreshed. A direct VeApexToken transfer outside the vault is just a normal NFT transfer; the SDK should treat vault stake/unstake as the canonical earning path.
353
+ ApexVault is custodial while a veNFT is staked. For staked veNFTs, route amount increases through `ApexVault.increaseAmountCallParameters(...)`, not raw `VeApexToken.depositFor(...)`, so ApexVault reward weights are refreshed. A direct VeApexToken transfer outside ApexVault is a normal NFT transfer; treat ApexVault stake and unstake as the canonical earning path.
352
354
 
353
355
  ### ABI refresh
354
356