@aspan/sdk 0.2.0 → 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 +32 -25
- package/dist/index.d.mts +325 -217
- package/dist/index.d.ts +325 -217
- package/dist/index.js +213 -208
- package/dist/index.mjs +212 -208
- package/package.json +1 -1
- package/src/__tests__/router.test.ts +378 -0
- package/src/abi/router.ts +153 -167
- package/src/index.ts +3 -2
- package/src/router.ts +48 -62
- package/src/types.ts +28 -12
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),
|
|
@@ -167,7 +166,7 @@ const hash = await router.stakeAndMintApUSD(
|
|
|
167
166
|
// Or with full control
|
|
168
167
|
const hash = await router.stakeAndMint({
|
|
169
168
|
targetLST: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B", // slisBNB
|
|
170
|
-
|
|
169
|
+
isXBNB: false,
|
|
171
170
|
minMintOut: parseAmount("99"),
|
|
172
171
|
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
173
172
|
value: parseAmount("1"), // 1 BNB
|
|
@@ -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,15 +269,17 @@ 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
|
|
269
|
-
|
|
270
|
-
|
|
272
|
+
// Preview mint/redeem with LST (accurate with fees)
|
|
273
|
+
const apUSDOut = await router.previewMintApUSD(slisBNB, parseAmount("1"));
|
|
274
|
+
const xBNBOut = await router.previewMintXBNB(slisBNB, parseAmount("1"));
|
|
275
|
+
const lstFromApUSD = await router.previewRedeemApUSD(slisBNB, parseAmount("100"));
|
|
276
|
+
const lstFromXBNB = await router.previewRedeemXBNB(slisBNB, parseAmount("10"));
|
|
271
277
|
|
|
272
278
|
// Get token addresses
|
|
273
279
|
const wbnb = await router.getWBNB();
|
|
274
280
|
const usdt = await router.getUSDT();
|
|
275
281
|
const slisBNB = await router.getSlisBNB();
|
|
282
|
+
const wclisBNB = await router.getWclisBNB();
|
|
276
283
|
```
|
|
277
284
|
|
|
278
285
|
---
|
|
@@ -758,7 +765,7 @@ displayDashboard();
|
|
|
758
765
|
| Category | Methods |
|
|
759
766
|
|----------|---------|
|
|
760
767
|
| **Config** | `getDefaultLST()`, `isSupportedInputToken()`, `isSupportedLST()`, `getDiamond()` |
|
|
761
|
-
| **Preview** | `
|
|
768
|
+
| **Preview** | `previewMintApUSD()`, `previewMintXBNB()`, `previewRedeemApUSD()`, `previewRedeemXBNB()` |
|
|
762
769
|
| **Unstake** | `getUserWithdrawalIndices()`, `getWithdrawalStatus()` |
|
|
763
770
|
| **Addresses** | `getWBNB()`, `getUSDT()`, `getUSDC()`, `getSlisBNB()`, `getAsBNB()`, `getWclisBNB()`, `getApUSD()`, `getXBNB()` |
|
|
764
771
|
|
|
@@ -769,7 +776,7 @@ displayDashboard();
|
|
|
769
776
|
| **Swap+Mint** | `swapAndMintApUSD()`, `swapAndMintXBNB()`, `swapAndMintApUSDDefault()`, `swapAndMintXBNBDefault()` |
|
|
770
777
|
| **Stake+Mint** | `stakeAndMint()`, `stakeAndMintApUSD()`, `stakeAndMintXBNB()` |
|
|
771
778
|
| **Direct** | `mintApUSD()`, `mintXBNB()`, `redeemApUSD()`, `redeemXBNB()` |
|
|
772
|
-
| **Redeem+Swap** | `redeemApUSDAndSwap()`, `redeemXBNBAndSwap()
|
|
779
|
+
| **Redeem+Swap** | `redeemApUSDAndSwap()`, `redeemXBNBAndSwap()` (V3 path) |
|
|
773
780
|
| **Native Unstake** | `redeemApUSDAndRequestUnstake()`, `redeemXBNBAndRequestUnstake()`, `claimUnstake()` |
|
|
774
781
|
|
|
775
782
|
---
|