@aspan/sdk 0.2.1 → 0.2.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/src/router.ts CHANGED
@@ -27,9 +27,7 @@ import type {
27
27
  RouterRedeemApUSDParams,
28
28
  RouterRedeemXBNBParams,
29
29
  RouterRedeemAndSwapParams,
30
- RouterRedeemAndUnstakeParams,
31
30
  WithdrawalRequestInfo,
32
- ExpectedOutput,
33
31
  } from "./types";
34
32
 
35
33
  // ============ Configuration ============
@@ -118,50 +116,6 @@ export class AspanRouterReadClient {
118
116
  });
119
117
  }
120
118
 
121
- /**
122
- * Get expected output from a swap and mint operation
123
- */
124
- async getExpectedMintOutput(
125
- inputToken: Address,
126
- inputAmount: bigint,
127
- targetLST: Address,
128
- isXBNB: boolean
129
- ): Promise<ExpectedOutput> {
130
- const result = await this.publicClient.readContract({
131
- address: this.routerAddress,
132
- abi: RouterABI,
133
- functionName: "getExpectedMintOutput",
134
- args: [inputToken, inputAmount, targetLST, isXBNB],
135
- });
136
-
137
- return {
138
- expectedLST: result[0],
139
- expectedMint: result[1],
140
- };
141
- }
142
-
143
- /**
144
- * Get expected output from a redeem and swap operation
145
- */
146
- async getExpectedRedeemOutput(
147
- isXBNB: boolean,
148
- redeemAmount: bigint,
149
- lst: Address,
150
- outputToken: Address
151
- ): Promise<ExpectedOutput> {
152
- const result = await this.publicClient.readContract({
153
- address: this.routerAddress,
154
- abi: RouterABI,
155
- functionName: "getExpectedRedeemOutput",
156
- args: [isXBNB, redeemAmount, lst, outputToken],
157
- });
158
-
159
- return {
160
- expectedLST: result[0],
161
- expectedMint: result[1],
162
- };
163
- }
164
-
165
119
  /**
166
120
  * Preview apUSD mint output for a given LST amount
167
121
  */
@@ -315,7 +269,7 @@ export class AspanRouterReadClient {
315
269
  * Full client with write capabilities for AspanRouter
316
270
  */
317
271
  export class AspanRouterClient extends AspanRouterReadClient {
318
- private readonly walletClient: WalletClient;
272
+ public readonly walletClient: WalletClient;
319
273
 
320
274
  constructor(config: AspanRouterWriteClientConfig) {
321
275
  super(config);
@@ -357,10 +311,8 @@ export class AspanRouterClient extends AspanRouterReadClient {
357
311
  targetLST: params.swapParams.targetLST,
358
312
  minLSTOut: params.swapParams.minLSTOut,
359
313
  poolFee: params.swapParams.poolFee,
360
- useV2: params.swapParams.useV2,
361
314
  },
362
315
  {
363
- mintXBNB: params.mintParams.mintXBNB,
364
316
  minMintOut: params.mintParams.minMintOut,
365
317
  recipient: params.mintParams.recipient,
366
318
  deadline: params.mintParams.deadline,
@@ -392,10 +344,8 @@ export class AspanRouterClient extends AspanRouterReadClient {
392
344
  targetLST: params.swapParams.targetLST,
393
345
  minLSTOut: params.swapParams.minLSTOut,
394
346
  poolFee: params.swapParams.poolFee,
395
- useV2: params.swapParams.useV2,
396
347
  },
397
348
  {
398
- mintXBNB: params.mintParams.mintXBNB,
399
349
  minMintOut: params.mintParams.minMintOut,
400
350
  recipient: params.mintParams.recipient,
401
351
  deadline: params.mintParams.deadline,
@@ -564,7 +514,8 @@ export class AspanRouterClient extends AspanRouterReadClient {
564
514
  // ============ Redeem and Swap Functions ============
565
515
 
566
516
  /**
567
- * Redeem apUSD and swap LST to output token
517
+ * Redeem apUSD and swap LST to output token via V3 path
518
+ * @param params.path - PancakeSwap V3 encoded path (use encodeV3Path helper)
568
519
  */
569
520
  async redeemApUSDAndSwap(params: RouterRedeemAndSwapParams): Promise<Hash> {
570
521
  return this.walletClient.writeContract({
@@ -576,17 +527,16 @@ export class AspanRouterClient extends AspanRouterReadClient {
576
527
  args: [
577
528
  params.lst,
578
529
  params.amount,
579
- params.outputToken,
530
+ params.path,
580
531
  params.minOut,
581
532
  params.deadline,
582
- params.useV2,
583
- params.poolFee,
584
533
  ],
585
534
  });
586
535
  }
587
536
 
588
537
  /**
589
- * Redeem xBNB and swap LST to output token
538
+ * Redeem xBNB and swap LST to output token via V3 path
539
+ * @param params.path - PancakeSwap V3 encoded path (use encodeV3Path helper)
590
540
  */
591
541
  async redeemXBNBAndSwap(params: RouterRedeemAndSwapParams): Promise<Hash> {
592
542
  return this.walletClient.writeContract({
@@ -598,47 +548,13 @@ export class AspanRouterClient extends AspanRouterReadClient {
598
548
  args: [
599
549
  params.lst,
600
550
  params.amount,
601
- params.outputToken,
551
+ params.path,
602
552
  params.minOut,
603
553
  params.deadline,
604
- params.useV2,
605
- params.poolFee,
606
554
  ],
607
555
  });
608
556
  }
609
557
 
610
- /**
611
- * Redeem apUSD and instantly unstake LST to native BNB via DEX
612
- */
613
- async redeemApUSDAndUnstake(
614
- params: RouterRedeemAndUnstakeParams
615
- ): Promise<Hash> {
616
- return this.walletClient.writeContract({
617
- chain: this.chain,
618
- account: this.walletClient.account!,
619
- address: this.routerAddress,
620
- abi: RouterABI,
621
- functionName: "redeemApUSDAndUnstake",
622
- args: [params.lst, params.amount, params.minBNBOut, params.deadline],
623
- });
624
- }
625
-
626
- /**
627
- * Redeem xBNB and instantly unstake LST to native BNB via DEX
628
- */
629
- async redeemXBNBAndUnstake(
630
- params: RouterRedeemAndUnstakeParams
631
- ): Promise<Hash> {
632
- return this.walletClient.writeContract({
633
- chain: this.chain,
634
- account: this.walletClient.account!,
635
- address: this.routerAddress,
636
- abi: RouterABI,
637
- functionName: "redeemXBNBAndUnstake",
638
- args: [params.lst, params.amount, params.minBNBOut, params.deadline],
639
- });
640
- }
641
-
642
558
  // ============ Native Unstake Functions ============
643
559
 
644
560
  /**
package/src/types.ts CHANGED
@@ -258,14 +258,10 @@ export interface RouterSwapParams {
258
258
  minLSTOut: bigint;
259
259
  /** PancakeSwap V3 pool fee tier (500, 2500, 10000) */
260
260
  poolFee: number;
261
- /** true = PancakeSwap V2, false = V3 */
262
- useV2: boolean;
263
261
  }
264
262
 
265
263
  /** Router mint parameters */
266
264
  export interface RouterMintParams {
267
- /** true = mint xBNB, false = mint apUSD */
268
- mintXBNB: boolean;
269
265
  /** Minimum output to receive (slippage protection) */
270
266
  minMintOut: bigint;
271
267
  /** Recipient of minted tokens (address(0) = msg.sender) */
@@ -348,22 +344,42 @@ export interface RouterRedeemXBNBParams {
348
344
  minOut?: bigint;
349
345
  }
350
346
 
351
- /** Parameters for redeemAndSwap functions */
347
+ /** Parameters for redeemAndSwap functions (uses PancakeSwap V3 path) */
352
348
  export interface RouterRedeemAndSwapParams {
353
349
  /** LST to redeem */
354
350
  lst: Address;
355
351
  /** Amount to redeem (apUSD or xBNB) */
356
352
  amount: bigint;
357
- /** Output token (address(0) for native BNB) */
358
- outputToken: Address;
353
+ /**
354
+ * PancakeSwap V3 encoded swap path (LST → ... → outputToken)
355
+ * Use encodeV3Path() helper or get from PancakeSwap Quoter
356
+ * Example: slisBNB → WBNB → USDT
357
+ */
358
+ path: `0x${string}`;
359
359
  /** Minimum output to receive */
360
360
  minOut: bigint;
361
361
  /** Transaction deadline timestamp */
362
362
  deadline: bigint;
363
- /** true = PancakeSwap V2, false = V3 */
364
- useV2: boolean;
365
- /** V3 pool fee tier (ignored if useV2) */
366
- poolFee: number;
363
+ }
364
+
365
+ /**
366
+ * Encode a PancakeSwap V3 swap path
367
+ * @param tokens Array of token addresses in order
368
+ * @param fees Array of pool fees between each token pair
369
+ * @returns Encoded path bytes
370
+ */
371
+ export function encodeV3Path(tokens: Address[], fees: number[]): `0x${string}` {
372
+ if (tokens.length < 2) throw new Error("Path must have at least 2 tokens");
373
+ if (fees.length !== tokens.length - 1) throw new Error("Fees length must be tokens.length - 1");
374
+
375
+ let path = tokens[0].toLowerCase().slice(2); // Remove 0x prefix
376
+ for (let i = 0; i < fees.length; i++) {
377
+ // Fee is 3 bytes (uint24)
378
+ const feeHex = fees[i].toString(16).padStart(6, "0");
379
+ path += feeHex;
380
+ path += tokens[i + 1].toLowerCase().slice(2);
381
+ }
382
+ return `0x${path}`;
367
383
  }
368
384
 
369
385
  /** Parameters for redeemAndUnstake functions */