@aspan/sdk 0.1.8 → 0.2.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 +241 -0
- package/dist/index.d.mts +1287 -1
- package/dist/index.d.ts +1287 -1
- package/dist/index.js +1168 -0
- package/dist/index.mjs +1166 -0
- package/package.json +1 -1
- package/src/abi/router.ts +619 -0
- package/src/index.ts +35 -0
- package/src/router.ts +756 -0
- package/src/types.ts +218 -0
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ pnpm add @aspan/sdk
|
|
|
16
16
|
| Contract | Address |
|
|
17
17
|
|----------|---------|
|
|
18
18
|
| **Diamond (Main Entry)** | `0x10d25Ae0690533e0BA9E64EC7ae77dbD4fE8A46f` |
|
|
19
|
+
| **Router** | `0x46d4Bb3bB2d0A0a85739A6d467eFB3025388AE2E` |
|
|
19
20
|
| **ApUSD** | `0x1977097E2E5697A6DD91b6732F368a14F50f6B3d` |
|
|
20
21
|
| **XBNB** | `0xB78eB4d5928bAb158Eb23c3154544084cD2661d5` |
|
|
21
22
|
| **SApUSD** | `0xE2BE739C4aA4126ee72D612d9548C38B1B0e5A1b` |
|
|
@@ -85,6 +86,218 @@ const hash = await client.mintApUSD({
|
|
|
85
86
|
|
|
86
87
|
---
|
|
87
88
|
|
|
89
|
+
## Router (One-Click Operations)
|
|
90
|
+
|
|
91
|
+
AspanRouter is a periphery contract that enables users to mint/redeem apUSD or xBNB in a single transaction using common tokens like USDT, USDC, BNB, or WBNB. The router automatically handles DEX swaps, LST staking, and minting.
|
|
92
|
+
|
|
93
|
+
### Router Client Setup
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { createRouterClient, AspanRouterClient } from "@aspan/sdk";
|
|
97
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
98
|
+
import { zeroAddress } from "viem";
|
|
99
|
+
|
|
100
|
+
const ROUTER = "0x46d4Bb3bB2d0A0a85739A6d467eFB3025388AE2E";
|
|
101
|
+
|
|
102
|
+
// Node.js
|
|
103
|
+
const account = privateKeyToAccount("0x...");
|
|
104
|
+
const router = createRouterClient(ROUTER, account);
|
|
105
|
+
|
|
106
|
+
// Browser (wagmi)
|
|
107
|
+
const router = new AspanRouterClient({
|
|
108
|
+
routerAddress: ROUTER,
|
|
109
|
+
walletClient, // from useWalletClient()
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Swap USDT/USDC → apUSD (One-Click)
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { parseAmount, type SwapAndMintParams } from "@aspan/sdk";
|
|
117
|
+
import { zeroAddress } from "viem";
|
|
118
|
+
|
|
119
|
+
const USDT = "0x55d398326f99059fF775485246999027B3197955";
|
|
120
|
+
|
|
121
|
+
// Full control with SwapParams + MintParams
|
|
122
|
+
const params: SwapAndMintParams = {
|
|
123
|
+
swapParams: {
|
|
124
|
+
inputToken: USDT,
|
|
125
|
+
inputAmount: parseAmount("100"), // 100 USDT
|
|
126
|
+
targetLST: zeroAddress, // Use default LST
|
|
127
|
+
minLSTOut: 0n, // Or set slippage protection
|
|
128
|
+
poolFee: 2500, // 0.25% V3 pool fee
|
|
129
|
+
useV2: true, // Use PancakeSwap V2
|
|
130
|
+
},
|
|
131
|
+
mintParams: {
|
|
132
|
+
mintXBNB: false, // Mint apUSD
|
|
133
|
+
minMintOut: parseAmount("99"), // Min 99 apUSD (1% slippage)
|
|
134
|
+
recipient: zeroAddress, // Send to msg.sender
|
|
135
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Approve USDT first, then swap+mint
|
|
140
|
+
const hash = await router.swapAndMintApUSD(params);
|
|
141
|
+
await router.waitForTransaction(hash);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Simplified: Swap → apUSD (Default LST)
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
// Simpler API using default LST and V2
|
|
148
|
+
const hash = await router.swapAndMintApUSDDefault({
|
|
149
|
+
inputToken: USDT,
|
|
150
|
+
inputAmount: parseAmount("100"),
|
|
151
|
+
minMintOut: parseAmount("99"),
|
|
152
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Stake Native BNB → apUSD (Bypasses DEX)
|
|
157
|
+
|
|
158
|
+
Direct BNB staking gets better rates for large amounts by bypassing DEX.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// Stake BNB directly to Lista/Astherus → mint apUSD
|
|
162
|
+
const hash = await router.stakeAndMintApUSD(
|
|
163
|
+
parseAmount("99"), // minMintOut
|
|
164
|
+
parseAmount("1"), // 1 BNB to stake (sent as value)
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
// Or with full control
|
|
168
|
+
const hash = await router.stakeAndMint({
|
|
169
|
+
targetLST: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B", // slisBNB
|
|
170
|
+
isXBNB: false,
|
|
171
|
+
minMintOut: parseAmount("99"),
|
|
172
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
173
|
+
value: parseAmount("1"), // 1 BNB
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Swap → xBNB (Leveraged Long)
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// Full params
|
|
181
|
+
const hash = await router.swapAndMintXBNB(params);
|
|
182
|
+
|
|
183
|
+
// Or simplified
|
|
184
|
+
const hash = await router.swapAndMintXBNBDefault({
|
|
185
|
+
inputToken: USDT,
|
|
186
|
+
inputAmount: parseAmount("1000"),
|
|
187
|
+
minMintOut: parseAmount("1"), // Min 1 xBNB
|
|
188
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Or stake BNB directly
|
|
192
|
+
const hash = await router.stakeAndMintXBNB(parseAmount("1"), parseAmount("10"));
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Direct Mint/Redeem via Router
|
|
196
|
+
|
|
197
|
+
If you already have LST, use direct functions (still routes through Diamond):
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
// Mint apUSD with LST
|
|
201
|
+
const hash = await router.mintApUSD({
|
|
202
|
+
lst: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B", // slisBNB
|
|
203
|
+
lstAmount: parseAmount("10"),
|
|
204
|
+
minOut: parseAmount("99"),
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Redeem apUSD for LST
|
|
208
|
+
const hash = await router.redeemApUSD({
|
|
209
|
+
lst: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B",
|
|
210
|
+
apUSDAmount: parseAmount("100"),
|
|
211
|
+
minOut: parseAmount("0.9"),
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Redeem + Swap to USDT/BNB
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
// Redeem apUSD and swap LST to USDT
|
|
219
|
+
const hash = await router.redeemApUSDAndSwap({
|
|
220
|
+
lst: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B",
|
|
221
|
+
amount: parseAmount("100"), // 100 apUSD
|
|
222
|
+
outputToken: USDT, // Get USDT
|
|
223
|
+
minOut: parseAmount("99"), // Min 99 USDT
|
|
224
|
+
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
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Native Unstake (7-15 Day Unbonding)
|
|
239
|
+
|
|
240
|
+
For no-slippage BNB redemption, use Lista's native unstake:
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
// Request unstake (starts 7-15 day unbonding period)
|
|
244
|
+
const hash = await router.redeemApUSDAndRequestUnstake(parseAmount("100"));
|
|
245
|
+
const receipt = await router.waitForTransaction(hash);
|
|
246
|
+
// Parse event to get requestIndex...
|
|
247
|
+
|
|
248
|
+
// Check withdrawal status
|
|
249
|
+
const indices = await router.getUserWithdrawalIndices(account.address);
|
|
250
|
+
for (const idx of indices) {
|
|
251
|
+
const status = await router.getWithdrawalStatus(idx);
|
|
252
|
+
console.log(`Request ${idx}: claimable=${status.isClaimable}, amount=${status.bnbAmount}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Claim BNB after unbonding
|
|
256
|
+
const hash = await router.claimUnstake(requestIndex);
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Router View Functions
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
// Check supported tokens
|
|
263
|
+
const defaultLST = await router.getDefaultLST();
|
|
264
|
+
const isSupported = await router.isSupportedInputToken(USDT);
|
|
265
|
+
const isLSTSupported = await router.isSupportedLST(slisBNB);
|
|
266
|
+
|
|
267
|
+
// Preview swap + mint output (accurate calculation with fees)
|
|
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)
|
|
288
|
+
const apUSDOut = await router.previewMintApUSD(slisBNB, parseAmount("1"));
|
|
289
|
+
const xBNBOut = await router.previewMintXBNB(slisBNB, parseAmount("1"));
|
|
290
|
+
const lstFromApUSD = await router.previewRedeemApUSD(slisBNB, parseAmount("100"));
|
|
291
|
+
const lstFromXBNB = await router.previewRedeemXBNB(slisBNB, parseAmount("10"));
|
|
292
|
+
|
|
293
|
+
// Get token addresses
|
|
294
|
+
const wbnb = await router.getWBNB();
|
|
295
|
+
const usdt = await router.getUSDT();
|
|
296
|
+
const slisBNB = await router.getSlisBNB();
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
88
301
|
## User Flows
|
|
89
302
|
|
|
90
303
|
### Flow 1: Mint apUSD (Stablecoin)
|
|
@@ -561,6 +774,27 @@ displayDashboard();
|
|
|
561
774
|
| **Pool** | `mintApUSD()`, `redeemApUSD()`, `mintXBNB()`, `redeemXBNB()` |
|
|
562
775
|
| **Stability Pool** | `deposit()`, `withdraw()`, `withdrawAssets()`, `harvestYield()` |
|
|
563
776
|
|
|
777
|
+
### Router View Functions
|
|
778
|
+
|
|
779
|
+
| Category | Methods |
|
|
780
|
+
|----------|---------|
|
|
781
|
+
| **Config** | `getDefaultLST()`, `isSupportedInputToken()`, `isSupportedLST()`, `getDiamond()` |
|
|
782
|
+
| **Preview Swap+Mint** | `getExpectedMintOutput()` (swap → LST → mint) |
|
|
783
|
+
| **Preview Redeem+Swap** | `getExpectedRedeemOutput()` (redeem → LST → swap) |
|
|
784
|
+
| **Preview Direct** | `previewMintApUSD()`, `previewMintXBNB()`, `previewRedeemApUSD()`, `previewRedeemXBNB()` |
|
|
785
|
+
| **Unstake** | `getUserWithdrawalIndices()`, `getWithdrawalStatus()` |
|
|
786
|
+
| **Addresses** | `getWBNB()`, `getUSDT()`, `getUSDC()`, `getSlisBNB()`, `getAsBNB()`, `getWclisBNB()`, `getApUSD()`, `getXBNB()` |
|
|
787
|
+
|
|
788
|
+
### Router Write Functions
|
|
789
|
+
|
|
790
|
+
| Category | Methods |
|
|
791
|
+
|----------|---------|
|
|
792
|
+
| **Swap+Mint** | `swapAndMintApUSD()`, `swapAndMintXBNB()`, `swapAndMintApUSDDefault()`, `swapAndMintXBNBDefault()` |
|
|
793
|
+
| **Stake+Mint** | `stakeAndMint()`, `stakeAndMintApUSD()`, `stakeAndMintXBNB()` |
|
|
794
|
+
| **Direct** | `mintApUSD()`, `mintXBNB()`, `redeemApUSD()`, `redeemXBNB()` |
|
|
795
|
+
| **Redeem+Swap** | `redeemApUSDAndSwap()`, `redeemXBNBAndSwap()`, `redeemApUSDAndUnstake()`, `redeemXBNBAndUnstake()` |
|
|
796
|
+
| **Native Unstake** | `redeemApUSDAndRequestUnstake()`, `redeemXBNBAndRequestUnstake()`, `claimUnstake()` |
|
|
797
|
+
|
|
564
798
|
---
|
|
565
799
|
|
|
566
800
|
## Utility Functions
|
|
@@ -587,10 +821,17 @@ import {
|
|
|
587
821
|
import {
|
|
588
822
|
createAspanTestnetReadClient,
|
|
589
823
|
createAspanTestnetClient,
|
|
824
|
+
createRouterTestnetReadClient,
|
|
825
|
+
createRouterTestnetClient,
|
|
590
826
|
} from "@aspan/sdk";
|
|
591
827
|
|
|
828
|
+
// Diamond client (testnet)
|
|
592
829
|
const client = createAspanTestnetReadClient("0x...");
|
|
593
830
|
const writeClient = createAspanTestnetClient("0x...", account);
|
|
831
|
+
|
|
832
|
+
// Router client (testnet)
|
|
833
|
+
const routerRead = createRouterTestnetReadClient("0x...");
|
|
834
|
+
const routerWrite = createRouterTestnetClient("0x...", account);
|
|
594
835
|
```
|
|
595
836
|
|
|
596
837
|
## License
|