@apex_labs/sdk 0.1.0 → 0.1.1

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,38 @@ 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 and support cleanup calls such as `refundETH`, `sweepToken`, and `unwrapWETH9`.
246
246
 
247
247
  The mixed periphery is exact-input only. Use the CL-only `SwapRouter`/`QuoterV2` for CL exact-output routes.
248
248
 
249
249
  ### CL farm UX
250
250
 
251
- Use `ApexCLFarm` for staked CL positions. It encodes the Apex-safe paths instead of making the frontend assemble Chef calls by hand.
251
+ Use `CLMasterChef` for staked CL positions. It encodes the supported paths without requiring applications to assemble Chef calls directly.
252
252
 
253
253
  ```ts
254
- const { calldata, value } = ApexCLFarm.mintAndStakeCallParameters(
254
+ const { calldata, value } = CLMasterChef.mintAndStakeCallParameters(
255
255
  {
256
256
  token0: tokenA.address,
257
257
  token1: tokenB.address,
258
- fee: ApexFeeAmount.FEE_0_30,
258
+ fee: CLFeeAmount.FEE_0_30,
259
259
  tickLower,
260
260
  tickUpper,
261
261
  amount0Desired,
@@ -272,19 +272,19 @@ const { calldata, value } = ApexCLFarm.mintAndStakeCallParameters(
272
272
  );
273
273
  ```
274
274
 
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.
275
+ `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
276
 
277
277
  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
278
 
279
279
  For fee collection on staked NFTs, prefer `collectCallParameters` or `decreaseAndCollectCallParameters`:
280
280
 
281
281
  ```ts
282
- const collect = ApexCLFarm.collectCallParameters({
282
+ const collect = CLMasterChef.collectCallParameters({
283
283
  tokenId,
284
284
  recipient: account,
285
285
  });
286
286
 
287
- const exitPart = ApexCLFarm.decreaseAndCollectCallParameters(
287
+ const exitPart = CLMasterChef.decreaseAndCollectCallParameters(
288
288
  { tokenId, liquidity, amount0Min, amount1Min, deadline },
289
289
  { tokenId, recipient: account },
290
290
  );
@@ -295,7 +295,7 @@ These helpers call `CLMasterChef.multicall(...)` and use `collectTo` with the in
295
295
  For a full exit, use `closeAndBurnCallParameters`:
296
296
 
297
297
  ```ts
298
- const close = ApexCLFarm.closeAndBurnCallParameters(
298
+ const close = CLMasterChef.closeAndBurnCallParameters(
299
299
  { tokenId, liquidity, amount0Min, amount1Min, deadline },
300
300
  { tokenId, recipient: account },
301
301
  );
@@ -303,17 +303,17 @@ const close = ApexCLFarm.closeAndBurnCallParameters(
303
303
 
304
304
  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
305
 
306
- ### Apex Vault UX
306
+ ### ApexVault UX
307
307
 
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.
308
+ 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
309
 
310
310
  ```ts
311
- const approveVault = ApexVaultPosition.encodeVeApexTokenApprove({
311
+ const approveVault = ApexVault.encodeVeApexTokenApprove({
312
312
  tokenId,
313
313
  spender: apexVault,
314
314
  });
315
315
 
316
- const stake = ApexVaultPosition.stakeCallParameters(tokenId, {
316
+ const stake = ApexVault.stakeCallParameters(tokenId, {
317
317
  rewardConfigs: [
318
318
  { rewardToken: weth, bps: 5_000 },
319
319
  { rewardToken: usdc, bps: 2_000 },
@@ -327,28 +327,28 @@ The helper rejects configs that do not sum to exactly `10_000` bps, repeat a rew
327
327
  For an existing staked veNFT:
328
328
 
329
329
  ```ts
330
- const updateConfig = ApexVaultPosition.setUserConfigCallParameters(tokenId, {
330
+ const updateConfig = ApexVault.setUserConfigCallParameters(tokenId, {
331
331
  rewardConfigs: [{ rewardToken: weth, bps: 7_000 }],
332
332
  compoundBps: 3_000,
333
333
  });
334
334
 
335
- const claim = ApexVaultPosition.claimCallParameters({
335
+ const claim = ApexVault.claimCallParameters({
336
336
  tokenId,
337
337
  rewardTokens: [weth, usdc],
338
338
  });
339
339
 
340
- const extend = ApexVaultPosition.extendLockCallParameters({
340
+ const extend = ApexVault.extendLockCallParameters({
341
341
  tokenId,
342
342
  lockDuration: 26n * 7n * 86_400n,
343
343
  });
344
344
 
345
- const increase = ApexVaultPosition.increaseAmountCallParameters({
345
+ const increase = ApexVault.increaseAmountCallParameters({
346
346
  tokenId,
347
347
  amount,
348
348
  });
349
349
  ```
350
350
 
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.
351
+ 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
352
 
353
353
  ### ABI refresh
354
354