@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/README.md +27 -43
- package/dist/index.d.mts +252 -248
- package/dist/index.d.ts +252 -248
- package/dist/index.js +144 -258
- package/dist/index.mjs +143 -258
- package/package.json +1 -1
- package/src/__tests__/router.test.ts +378 -0
- package/src/abi/router.ts +123 -202
- package/src/index.ts +3 -2
- package/src/router.ts +7 -91
- package/src/types.ts +27 -11
package/README.md
CHANGED
|
@@ -16,7 +16,8 @@ pnpm add @aspan/sdk
|
|
|
16
16
|
| Contract | Address |
|
|
17
17
|
|----------|---------|
|
|
18
18
|
| **Diamond (Main Entry)** | `0x10d25Ae0690533e0BA9E64EC7ae77dbD4fE8A46f` |
|
|
19
|
-
| **Router** | `
|
|
19
|
+
| **Router** | `0xf63f34f7e9608ae7d3a6f5b06ce423d9f9043648` |
|
|
20
|
+
| **wclisBNB** | `0x439faaC2229559121C4Ad4fd8B3FE13Dff038046` |
|
|
20
21
|
| **ApUSD** | `0x1977097E2E5697A6DD91b6732F368a14F50f6B3d` |
|
|
21
22
|
| **XBNB** | `0xB78eB4d5928bAb158Eb23c3154544084cD2661d5` |
|
|
22
23
|
| **SApUSD** | `0xE2BE739C4aA4126ee72D612d9548C38B1B0e5A1b` |
|
|
@@ -97,7 +98,7 @@ import { createRouterClient, AspanRouterClient } from "@aspan/sdk";
|
|
|
97
98
|
import { privateKeyToAccount } from "viem/accounts";
|
|
98
99
|
import { zeroAddress } from "viem";
|
|
99
100
|
|
|
100
|
-
const ROUTER = "
|
|
101
|
+
const ROUTER = "0xf63f34f7e9608ae7d3a6f5b06ce423d9f9043648";
|
|
101
102
|
|
|
102
103
|
// Node.js
|
|
103
104
|
const account = privateKeyToAccount("0x...");
|
|
@@ -126,10 +127,8 @@ const params: SwapAndMintParams = {
|
|
|
126
127
|
targetLST: zeroAddress, // Use default LST
|
|
127
128
|
minLSTOut: 0n, // Or set slippage protection
|
|
128
129
|
poolFee: 2500, // 0.25% V3 pool fee
|
|
129
|
-
useV2: true, // Use PancakeSwap V2
|
|
130
130
|
},
|
|
131
131
|
mintParams: {
|
|
132
|
-
mintXBNB: false, // Mint apUSD
|
|
133
132
|
minMintOut: parseAmount("99"), // Min 99 apUSD (1% slippage)
|
|
134
133
|
recipient: zeroAddress, // Send to msg.sender
|
|
135
134
|
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
@@ -212,29 +211,35 @@ const hash = await router.redeemApUSD({
|
|
|
212
211
|
});
|
|
213
212
|
```
|
|
214
213
|
|
|
215
|
-
### Redeem + Swap to USDT/BNB
|
|
214
|
+
### Redeem + Swap to USDT/BNB (V3 Path)
|
|
216
215
|
|
|
217
216
|
```typescript
|
|
218
|
-
|
|
217
|
+
import { encodeV3Path } from "@aspan/sdk";
|
|
218
|
+
|
|
219
|
+
const SLISBNB = "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B";
|
|
220
|
+
const WBNB = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
|
|
221
|
+
const USDT = "0x55d398326f99059fF775485246999027B3197955";
|
|
222
|
+
|
|
223
|
+
// Encode V3 swap path: slisBNB → WBNB → USDT
|
|
224
|
+
// Use encodeV3Path helper or get optimal path from PancakeSwap Quoter
|
|
225
|
+
const path = encodeV3Path(
|
|
226
|
+
[SLISBNB, WBNB, USDT], // tokens
|
|
227
|
+
[500, 500] // pool fees (0.05% each hop)
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
// Redeem apUSD and swap LST to USDT via V3 path
|
|
219
231
|
const hash = await router.redeemApUSDAndSwap({
|
|
220
|
-
lst:
|
|
232
|
+
lst: SLISBNB,
|
|
221
233
|
amount: parseAmount("100"), // 100 apUSD
|
|
222
|
-
|
|
234
|
+
path, // V3 encoded path
|
|
223
235
|
minOut: parseAmount("99"), // Min 99 USDT
|
|
224
236
|
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
225
|
-
useV2: true,
|
|
226
|
-
poolFee: 2500,
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
// Redeem and get native BNB instantly (via DEX swap)
|
|
230
|
-
const hash = await router.redeemApUSDAndUnstake({
|
|
231
|
-
lst: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B",
|
|
232
|
-
amount: parseAmount("100"),
|
|
233
|
-
minBNBOut: parseAmount("0.1"),
|
|
234
|
-
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
235
237
|
});
|
|
236
238
|
```
|
|
237
239
|
|
|
240
|
+
> **Note**: For optimal swap paths and quotes, use PancakeSwap V3 Quoter contract:
|
|
241
|
+
> `0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997` (BSC Mainnet)
|
|
242
|
+
|
|
238
243
|
### Native Unstake (7-15 Day Unbonding)
|
|
239
244
|
|
|
240
245
|
For no-slippage BNB redemption, use Lista's native unstake:
|
|
@@ -264,27 +269,7 @@ const defaultLST = await router.getDefaultLST();
|
|
|
264
269
|
const isSupported = await router.isSupportedInputToken(USDT);
|
|
265
270
|
const isLSTSupported = await router.isSupportedLST(slisBNB);
|
|
266
271
|
|
|
267
|
-
// Preview
|
|
268
|
-
const mintOutput = await router.getExpectedMintOutput(
|
|
269
|
-
USDT, // inputToken
|
|
270
|
-
parseAmount("100"), // inputAmount
|
|
271
|
-
zeroAddress, // targetLST (use default)
|
|
272
|
-
false // isXBNB (false = apUSD)
|
|
273
|
-
);
|
|
274
|
-
console.log("Expected LST from swap:", formatAmount(mintOutput.expectedLST));
|
|
275
|
-
console.log("Expected apUSD after mint:", formatAmount(mintOutput.expectedMint));
|
|
276
|
-
|
|
277
|
-
// Preview redeem + swap output
|
|
278
|
-
const redeemOutput = await router.getExpectedRedeemOutput(
|
|
279
|
-
false, // isXBNB (false = apUSD)
|
|
280
|
-
parseAmount("100"), // redeemAmount
|
|
281
|
-
slisBNB, // LST to redeem
|
|
282
|
-
USDT // outputToken
|
|
283
|
-
);
|
|
284
|
-
console.log("Expected LST from redeem:", formatAmount(redeemOutput.expectedLST));
|
|
285
|
-
console.log("Expected USDT from swap:", formatAmount(redeemOutput.expectedMint));
|
|
286
|
-
|
|
287
|
-
// Preview mint/redeem with LST (no swap, accurate with fees)
|
|
272
|
+
// Preview mint/redeem with LST (accurate with fees)
|
|
288
273
|
const apUSDOut = await router.previewMintApUSD(slisBNB, parseAmount("1"));
|
|
289
274
|
const xBNBOut = await router.previewMintXBNB(slisBNB, parseAmount("1"));
|
|
290
275
|
const lstFromApUSD = await router.previewRedeemApUSD(slisBNB, parseAmount("100"));
|
|
@@ -294,6 +279,7 @@ const lstFromXBNB = await router.previewRedeemXBNB(slisBNB, parseAmount("10"));
|
|
|
294
279
|
const wbnb = await router.getWBNB();
|
|
295
280
|
const usdt = await router.getUSDT();
|
|
296
281
|
const slisBNB = await router.getSlisBNB();
|
|
282
|
+
const wclisBNB = await router.getWclisBNB();
|
|
297
283
|
```
|
|
298
284
|
|
|
299
285
|
---
|
|
@@ -779,9 +765,7 @@ displayDashboard();
|
|
|
779
765
|
| Category | Methods |
|
|
780
766
|
|----------|---------|
|
|
781
767
|
| **Config** | `getDefaultLST()`, `isSupportedInputToken()`, `isSupportedLST()`, `getDiamond()` |
|
|
782
|
-
| **Preview
|
|
783
|
-
| **Preview Redeem+Swap** | `getExpectedRedeemOutput()` (redeem → LST → swap) |
|
|
784
|
-
| **Preview Direct** | `previewMintApUSD()`, `previewMintXBNB()`, `previewRedeemApUSD()`, `previewRedeemXBNB()` |
|
|
768
|
+
| **Preview** | `previewMintApUSD()`, `previewMintXBNB()`, `previewRedeemApUSD()`, `previewRedeemXBNB()` |
|
|
785
769
|
| **Unstake** | `getUserWithdrawalIndices()`, `getWithdrawalStatus()` |
|
|
786
770
|
| **Addresses** | `getWBNB()`, `getUSDT()`, `getUSDC()`, `getSlisBNB()`, `getAsBNB()`, `getWclisBNB()`, `getApUSD()`, `getXBNB()` |
|
|
787
771
|
|
|
@@ -792,7 +776,7 @@ displayDashboard();
|
|
|
792
776
|
| **Swap+Mint** | `swapAndMintApUSD()`, `swapAndMintXBNB()`, `swapAndMintApUSDDefault()`, `swapAndMintXBNBDefault()` |
|
|
793
777
|
| **Stake+Mint** | `stakeAndMint()`, `stakeAndMintApUSD()`, `stakeAndMintXBNB()` |
|
|
794
778
|
| **Direct** | `mintApUSD()`, `mintXBNB()`, `redeemApUSD()`, `redeemXBNB()` |
|
|
795
|
-
| **Redeem+Swap** | `redeemApUSDAndSwap()`, `redeemXBNBAndSwap()
|
|
779
|
+
| **Redeem+Swap** | `redeemApUSDAndSwap()`, `redeemXBNBAndSwap()` (V3 path) |
|
|
796
780
|
| **Native Unstake** | `redeemApUSDAndRequestUnstake()`, `redeemXBNBAndRequestUnstake()`, `claimUnstake()` |
|
|
797
781
|
|
|
798
782
|
---
|