@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 +74 -72
- package/dist/index.cjs +145 -84
- package/dist/index.d.cts +240 -194
- package/dist/index.d.ts +240 -194
- package/dist/index.js +126 -84
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Apex SDK
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
##
|
|
46
|
+
## Core exports
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
49
|
import {
|
|
50
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
ClassicChef,
|
|
55
|
+
CLMasterChef,
|
|
56
|
+
SmartRouter,
|
|
57
|
+
ApexVault,
|
|
58
|
+
getCLTickSpacing,
|
|
59
|
+
createCLPool,
|
|
60
60
|
computeCLPoolAddress,
|
|
61
61
|
computeClassicPoolAddress,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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:
|
|
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 =
|
|
103
|
+
const pool = createCLPool({
|
|
104
104
|
tokenA,
|
|
105
105
|
tokenB,
|
|
106
|
-
fee:
|
|
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
|
-
`
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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 =
|
|
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 `
|
|
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 =
|
|
171
|
+
const stakeClassic = ClassicChef.depositCallParameters({
|
|
172
172
|
pid,
|
|
173
173
|
amount,
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
-
const claimClassic =
|
|
176
|
+
const claimClassic = ClassicChef.harvestCallParameters({
|
|
177
177
|
pid,
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
-
const exitClassic =
|
|
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 =
|
|
189
|
+
const path = encodeMixedRouteToPath([
|
|
190
190
|
{
|
|
191
191
|
kind: "CL",
|
|
192
192
|
tokenIn: tokenA.address,
|
|
193
193
|
tokenOut: tokenB.address,
|
|
194
|
-
fee:
|
|
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
|
-
`
|
|
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 =
|
|
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 } =
|
|
214
|
+
const { path, flags } = encodeMixedRouteToPancakeQuoteParams(hops);
|
|
215
215
|
const quote = await publicClient.readContract({
|
|
216
216
|
address: apex.mixedQuoter,
|
|
217
|
-
abi:
|
|
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
|
-
|
|
227
|
+
SmartRouter.classicExactInputCallParameters(
|
|
228
228
|
{ amountIn, amountOutMin, path, recipient },
|
|
229
229
|
{ deadlineOrPreviousBlockhash: deadline },
|
|
230
230
|
);
|
|
231
231
|
|
|
232
232
|
// Classic stable section
|
|
233
|
-
|
|
233
|
+
SmartRouter.stableExactInputCallParameters(
|
|
234
234
|
{ amountIn, amountOutMin, path, flags, recipient },
|
|
235
235
|
{ deadlineOrPreviousBlockhash: deadline },
|
|
236
236
|
);
|
|
237
237
|
|
|
238
238
|
// CL section
|
|
239
|
-
|
|
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 `
|
|
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 `
|
|
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 } =
|
|
256
|
+
const { calldata, value } = CLMasterChef.mintAndStakeCallParameters(
|
|
255
257
|
{
|
|
256
258
|
token0: tokenA.address,
|
|
257
259
|
token1: tokenB.address,
|
|
258
|
-
fee:
|
|
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
|
|
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 =
|
|
284
|
+
const collect = CLMasterChef.collectCallParameters({
|
|
283
285
|
tokenId,
|
|
284
286
|
recipient: account,
|
|
285
287
|
});
|
|
286
288
|
|
|
287
|
-
const exitPart =
|
|
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 =
|
|
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
|
-
###
|
|
308
|
+
### ApexVault UX
|
|
307
309
|
|
|
308
|
-
Use `
|
|
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 =
|
|
313
|
+
const approveVault = ApexVault.encodeVeApexTokenApprove({
|
|
312
314
|
tokenId,
|
|
313
315
|
spender: apexVault,
|
|
314
316
|
});
|
|
315
317
|
|
|
316
|
-
const stake =
|
|
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 =
|
|
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 =
|
|
337
|
+
const claim = ApexVault.claimCallParameters({
|
|
336
338
|
tokenId,
|
|
337
339
|
rewardTokens: [weth, usdc],
|
|
338
340
|
});
|
|
339
341
|
|
|
340
|
-
const extend =
|
|
342
|
+
const extend = ApexVault.extendLockCallParameters({
|
|
341
343
|
tokenId,
|
|
342
344
|
lockDuration: 26n * 7n * 86_400n,
|
|
343
345
|
});
|
|
344
346
|
|
|
345
|
-
const increase =
|
|
347
|
+
const increase = ApexVault.increaseAmountCallParameters({
|
|
346
348
|
tokenId,
|
|
347
349
|
amount,
|
|
348
350
|
});
|
|
349
351
|
```
|
|
350
352
|
|
|
351
|
-
|
|
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
|
|