@aspan/sdk 0.2.0 → 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 CHANGED
@@ -167,7 +167,7 @@ const hash = await router.stakeAndMintApUSD(
167
167
  // Or with full control
168
168
  const hash = await router.stakeAndMint({
169
169
  targetLST: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B", // slisBNB
170
- mintXBNB: false,
170
+ isXBNB: false,
171
171
  minMintOut: parseAmount("99"),
172
172
  deadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
173
173
  value: parseAmount("1"), // 1 BNB
@@ -264,10 +264,31 @@ const defaultLST = await router.getDefaultLST();
264
264
  const isSupported = await router.isSupportedInputToken(USDT);
265
265
  const isLSTSupported = await router.isSupportedLST(slisBNB);
266
266
 
267
- // Preview swap output
268
- const output = await router.getExpectedOutput(USDT, parseAmount("100"), zeroAddress, false);
269
- console.log("Expected LST:", output.expectedLST);
270
- console.log("Expected apUSD:", output.expectedMint);
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"));
271
292
 
272
293
  // Get token addresses
273
294
  const wbnb = await router.getWBNB();
@@ -758,7 +779,9 @@ displayDashboard();
758
779
  | Category | Methods |
759
780
  |----------|---------|
760
781
  | **Config** | `getDefaultLST()`, `isSupportedInputToken()`, `isSupportedLST()`, `getDiamond()` |
761
- | **Preview** | `getExpectedOutput()` |
782
+ | **Preview Swap+Mint** | `getExpectedMintOutput()` (swap → LST → mint) |
783
+ | **Preview Redeem+Swap** | `getExpectedRedeemOutput()` (redeem → LST → swap) |
784
+ | **Preview Direct** | `previewMintApUSD()`, `previewMintXBNB()`, `previewRedeemApUSD()`, `previewRedeemXBNB()` |
762
785
  | **Unstake** | `getUserWithdrawalIndices()`, `getWithdrawalStatus()` |
763
786
  | **Addresses** | `getWBNB()`, `getUSDT()`, `getUSDC()`, `getSlisBNB()`, `getAsBNB()`, `getWclisBNB()`, `getApUSD()`, `getXBNB()` |
764
787
 
package/dist/index.d.mts CHANGED
@@ -233,7 +233,7 @@ interface StakeAndMintParams {
233
233
  /** Target LST (slisBNB, asBNB, wclisBNB) */
234
234
  targetLST: Address;
235
235
  /** true = mint xBNB, false = mint apUSD */
236
- mintXBNB: boolean;
236
+ isXBNB: boolean;
237
237
  /** Minimum output to receive */
238
238
  minMintOut: bigint;
239
239
  /** Transaction deadline timestamp */
@@ -593,7 +593,27 @@ declare class AspanRouterReadClient {
593
593
  /**
594
594
  * Get expected output from a swap and mint operation
595
595
  */
596
- getExpectedOutput(inputToken: Address, inputAmount: bigint, targetLST: Address, mintXBNB: boolean): Promise<ExpectedOutput>;
596
+ getExpectedMintOutput(inputToken: Address, inputAmount: bigint, targetLST: Address, isXBNB: boolean): Promise<ExpectedOutput>;
597
+ /**
598
+ * Get expected output from a redeem and swap operation
599
+ */
600
+ getExpectedRedeemOutput(isXBNB: boolean, redeemAmount: bigint, lst: Address, outputToken: Address): Promise<ExpectedOutput>;
601
+ /**
602
+ * Preview apUSD mint output for a given LST amount
603
+ */
604
+ previewMintApUSD(lst: Address, lstAmount: bigint): Promise<bigint>;
605
+ /**
606
+ * Preview xBNB mint output for a given LST amount
607
+ */
608
+ previewMintXBNB(lst: Address, lstAmount: bigint): Promise<bigint>;
609
+ /**
610
+ * Preview LST output for redeeming apUSD
611
+ */
612
+ previewRedeemApUSD(lst: Address, apUSDAmount: bigint): Promise<bigint>;
613
+ /**
614
+ * Preview LST output for redeeming xBNB
615
+ */
616
+ previewRedeemXBNB(lst: Address, xBNBAmount: bigint): Promise<bigint>;
597
617
  /**
598
618
  * Get user's withdrawal request indices
599
619
  */
@@ -1761,7 +1781,7 @@ declare const RouterABI: readonly [{
1761
1781
  readonly name: "targetLST";
1762
1782
  readonly type: "address";
1763
1783
  }, {
1764
- readonly name: "mintXBNB";
1784
+ readonly name: "isXBNB";
1765
1785
  readonly type: "bool";
1766
1786
  }, {
1767
1787
  readonly name: "minMintOut";
@@ -2104,7 +2124,7 @@ declare const RouterABI: readonly [{
2104
2124
  readonly stateMutability: "view";
2105
2125
  }, {
2106
2126
  readonly type: "function";
2107
- readonly name: "getExpectedOutput";
2127
+ readonly name: "getExpectedMintOutput";
2108
2128
  readonly inputs: readonly [{
2109
2129
  readonly name: "inputToken";
2110
2130
  readonly type: "address";
@@ -2115,7 +2135,7 @@ declare const RouterABI: readonly [{
2115
2135
  readonly name: "targetLST";
2116
2136
  readonly type: "address";
2117
2137
  }, {
2118
- readonly name: "mintXBNB";
2138
+ readonly name: "isXBNB";
2119
2139
  readonly type: "bool";
2120
2140
  }];
2121
2141
  readonly outputs: readonly [{
@@ -2126,6 +2146,90 @@ declare const RouterABI: readonly [{
2126
2146
  readonly type: "uint256";
2127
2147
  }];
2128
2148
  readonly stateMutability: "view";
2149
+ }, {
2150
+ readonly type: "function";
2151
+ readonly name: "getExpectedRedeemOutput";
2152
+ readonly inputs: readonly [{
2153
+ readonly name: "isXBNB";
2154
+ readonly type: "bool";
2155
+ }, {
2156
+ readonly name: "redeemAmount";
2157
+ readonly type: "uint256";
2158
+ }, {
2159
+ readonly name: "lst";
2160
+ readonly type: "address";
2161
+ }, {
2162
+ readonly name: "outputToken";
2163
+ readonly type: "address";
2164
+ }];
2165
+ readonly outputs: readonly [{
2166
+ readonly name: "expectedLST";
2167
+ readonly type: "uint256";
2168
+ }, {
2169
+ readonly name: "expectedOutput";
2170
+ readonly type: "uint256";
2171
+ }];
2172
+ readonly stateMutability: "view";
2173
+ }, {
2174
+ readonly type: "function";
2175
+ readonly name: "previewMintApUSD";
2176
+ readonly inputs: readonly [{
2177
+ readonly name: "lst";
2178
+ readonly type: "address";
2179
+ }, {
2180
+ readonly name: "lstAmount";
2181
+ readonly type: "uint256";
2182
+ }];
2183
+ readonly outputs: readonly [{
2184
+ readonly name: "apUSDAmount";
2185
+ readonly type: "uint256";
2186
+ }];
2187
+ readonly stateMutability: "view";
2188
+ }, {
2189
+ readonly type: "function";
2190
+ readonly name: "previewMintXBNB";
2191
+ readonly inputs: readonly [{
2192
+ readonly name: "lst";
2193
+ readonly type: "address";
2194
+ }, {
2195
+ readonly name: "lstAmount";
2196
+ readonly type: "uint256";
2197
+ }];
2198
+ readonly outputs: readonly [{
2199
+ readonly name: "xBNBAmount";
2200
+ readonly type: "uint256";
2201
+ }];
2202
+ readonly stateMutability: "view";
2203
+ }, {
2204
+ readonly type: "function";
2205
+ readonly name: "previewRedeemApUSD";
2206
+ readonly inputs: readonly [{
2207
+ readonly name: "lst";
2208
+ readonly type: "address";
2209
+ }, {
2210
+ readonly name: "apUSDAmount";
2211
+ readonly type: "uint256";
2212
+ }];
2213
+ readonly outputs: readonly [{
2214
+ readonly name: "lstAmount";
2215
+ readonly type: "uint256";
2216
+ }];
2217
+ readonly stateMutability: "view";
2218
+ }, {
2219
+ readonly type: "function";
2220
+ readonly name: "previewRedeemXBNB";
2221
+ readonly inputs: readonly [{
2222
+ readonly name: "lst";
2223
+ readonly type: "address";
2224
+ }, {
2225
+ readonly name: "xBNBAmount";
2226
+ readonly type: "uint256";
2227
+ }];
2228
+ readonly outputs: readonly [{
2229
+ readonly name: "lstAmount";
2230
+ readonly type: "uint256";
2231
+ }];
2232
+ readonly stateMutability: "view";
2129
2233
  }, {
2130
2234
  readonly type: "function";
2131
2235
  readonly name: "getUserWithdrawalIndices";
package/dist/index.d.ts CHANGED
@@ -233,7 +233,7 @@ interface StakeAndMintParams {
233
233
  /** Target LST (slisBNB, asBNB, wclisBNB) */
234
234
  targetLST: Address;
235
235
  /** true = mint xBNB, false = mint apUSD */
236
- mintXBNB: boolean;
236
+ isXBNB: boolean;
237
237
  /** Minimum output to receive */
238
238
  minMintOut: bigint;
239
239
  /** Transaction deadline timestamp */
@@ -593,7 +593,27 @@ declare class AspanRouterReadClient {
593
593
  /**
594
594
  * Get expected output from a swap and mint operation
595
595
  */
596
- getExpectedOutput(inputToken: Address, inputAmount: bigint, targetLST: Address, mintXBNB: boolean): Promise<ExpectedOutput>;
596
+ getExpectedMintOutput(inputToken: Address, inputAmount: bigint, targetLST: Address, isXBNB: boolean): Promise<ExpectedOutput>;
597
+ /**
598
+ * Get expected output from a redeem and swap operation
599
+ */
600
+ getExpectedRedeemOutput(isXBNB: boolean, redeemAmount: bigint, lst: Address, outputToken: Address): Promise<ExpectedOutput>;
601
+ /**
602
+ * Preview apUSD mint output for a given LST amount
603
+ */
604
+ previewMintApUSD(lst: Address, lstAmount: bigint): Promise<bigint>;
605
+ /**
606
+ * Preview xBNB mint output for a given LST amount
607
+ */
608
+ previewMintXBNB(lst: Address, lstAmount: bigint): Promise<bigint>;
609
+ /**
610
+ * Preview LST output for redeeming apUSD
611
+ */
612
+ previewRedeemApUSD(lst: Address, apUSDAmount: bigint): Promise<bigint>;
613
+ /**
614
+ * Preview LST output for redeeming xBNB
615
+ */
616
+ previewRedeemXBNB(lst: Address, xBNBAmount: bigint): Promise<bigint>;
597
617
  /**
598
618
  * Get user's withdrawal request indices
599
619
  */
@@ -1761,7 +1781,7 @@ declare const RouterABI: readonly [{
1761
1781
  readonly name: "targetLST";
1762
1782
  readonly type: "address";
1763
1783
  }, {
1764
- readonly name: "mintXBNB";
1784
+ readonly name: "isXBNB";
1765
1785
  readonly type: "bool";
1766
1786
  }, {
1767
1787
  readonly name: "minMintOut";
@@ -2104,7 +2124,7 @@ declare const RouterABI: readonly [{
2104
2124
  readonly stateMutability: "view";
2105
2125
  }, {
2106
2126
  readonly type: "function";
2107
- readonly name: "getExpectedOutput";
2127
+ readonly name: "getExpectedMintOutput";
2108
2128
  readonly inputs: readonly [{
2109
2129
  readonly name: "inputToken";
2110
2130
  readonly type: "address";
@@ -2115,7 +2135,7 @@ declare const RouterABI: readonly [{
2115
2135
  readonly name: "targetLST";
2116
2136
  readonly type: "address";
2117
2137
  }, {
2118
- readonly name: "mintXBNB";
2138
+ readonly name: "isXBNB";
2119
2139
  readonly type: "bool";
2120
2140
  }];
2121
2141
  readonly outputs: readonly [{
@@ -2126,6 +2146,90 @@ declare const RouterABI: readonly [{
2126
2146
  readonly type: "uint256";
2127
2147
  }];
2128
2148
  readonly stateMutability: "view";
2149
+ }, {
2150
+ readonly type: "function";
2151
+ readonly name: "getExpectedRedeemOutput";
2152
+ readonly inputs: readonly [{
2153
+ readonly name: "isXBNB";
2154
+ readonly type: "bool";
2155
+ }, {
2156
+ readonly name: "redeemAmount";
2157
+ readonly type: "uint256";
2158
+ }, {
2159
+ readonly name: "lst";
2160
+ readonly type: "address";
2161
+ }, {
2162
+ readonly name: "outputToken";
2163
+ readonly type: "address";
2164
+ }];
2165
+ readonly outputs: readonly [{
2166
+ readonly name: "expectedLST";
2167
+ readonly type: "uint256";
2168
+ }, {
2169
+ readonly name: "expectedOutput";
2170
+ readonly type: "uint256";
2171
+ }];
2172
+ readonly stateMutability: "view";
2173
+ }, {
2174
+ readonly type: "function";
2175
+ readonly name: "previewMintApUSD";
2176
+ readonly inputs: readonly [{
2177
+ readonly name: "lst";
2178
+ readonly type: "address";
2179
+ }, {
2180
+ readonly name: "lstAmount";
2181
+ readonly type: "uint256";
2182
+ }];
2183
+ readonly outputs: readonly [{
2184
+ readonly name: "apUSDAmount";
2185
+ readonly type: "uint256";
2186
+ }];
2187
+ readonly stateMutability: "view";
2188
+ }, {
2189
+ readonly type: "function";
2190
+ readonly name: "previewMintXBNB";
2191
+ readonly inputs: readonly [{
2192
+ readonly name: "lst";
2193
+ readonly type: "address";
2194
+ }, {
2195
+ readonly name: "lstAmount";
2196
+ readonly type: "uint256";
2197
+ }];
2198
+ readonly outputs: readonly [{
2199
+ readonly name: "xBNBAmount";
2200
+ readonly type: "uint256";
2201
+ }];
2202
+ readonly stateMutability: "view";
2203
+ }, {
2204
+ readonly type: "function";
2205
+ readonly name: "previewRedeemApUSD";
2206
+ readonly inputs: readonly [{
2207
+ readonly name: "lst";
2208
+ readonly type: "address";
2209
+ }, {
2210
+ readonly name: "apUSDAmount";
2211
+ readonly type: "uint256";
2212
+ }];
2213
+ readonly outputs: readonly [{
2214
+ readonly name: "lstAmount";
2215
+ readonly type: "uint256";
2216
+ }];
2217
+ readonly stateMutability: "view";
2218
+ }, {
2219
+ readonly type: "function";
2220
+ readonly name: "previewRedeemXBNB";
2221
+ readonly inputs: readonly [{
2222
+ readonly name: "lst";
2223
+ readonly type: "address";
2224
+ }, {
2225
+ readonly name: "xBNBAmount";
2226
+ readonly type: "uint256";
2227
+ }];
2228
+ readonly outputs: readonly [{
2229
+ readonly name: "lstAmount";
2230
+ readonly type: "uint256";
2231
+ }];
2232
+ readonly stateMutability: "view";
2129
2233
  }, {
2130
2234
  readonly type: "function";
2131
2235
  readonly name: "getUserWithdrawalIndices";
package/dist/index.js CHANGED
@@ -1536,7 +1536,7 @@ var RouterABI = [
1536
1536
  name: "stakeAndMint",
1537
1537
  inputs: [
1538
1538
  { name: "targetLST", type: "address" },
1539
- { name: "mintXBNB", type: "bool" },
1539
+ { name: "isXBNB", type: "bool" },
1540
1540
  { name: "minMintOut", type: "uint256" },
1541
1541
  { name: "deadline", type: "uint256" }
1542
1542
  ],
@@ -1761,15 +1761,15 @@ var RouterABI = [
1761
1761
  outputs: [{ name: "", type: "address" }],
1762
1762
  stateMutability: "view"
1763
1763
  },
1764
- // getExpectedOutput
1764
+ // getExpectedMintOutput
1765
1765
  {
1766
1766
  type: "function",
1767
- name: "getExpectedOutput",
1767
+ name: "getExpectedMintOutput",
1768
1768
  inputs: [
1769
1769
  { name: "inputToken", type: "address" },
1770
1770
  { name: "inputAmount", type: "uint256" },
1771
1771
  { name: "targetLST", type: "address" },
1772
- { name: "mintXBNB", type: "bool" }
1772
+ { name: "isXBNB", type: "bool" }
1773
1773
  ],
1774
1774
  outputs: [
1775
1775
  { name: "expectedLST", type: "uint256" },
@@ -1777,6 +1777,66 @@ var RouterABI = [
1777
1777
  ],
1778
1778
  stateMutability: "view"
1779
1779
  },
1780
+ // getExpectedRedeemOutput
1781
+ {
1782
+ type: "function",
1783
+ name: "getExpectedRedeemOutput",
1784
+ inputs: [
1785
+ { name: "isXBNB", type: "bool" },
1786
+ { name: "redeemAmount", type: "uint256" },
1787
+ { name: "lst", type: "address" },
1788
+ { name: "outputToken", type: "address" }
1789
+ ],
1790
+ outputs: [
1791
+ { name: "expectedLST", type: "uint256" },
1792
+ { name: "expectedOutput", type: "uint256" }
1793
+ ],
1794
+ stateMutability: "view"
1795
+ },
1796
+ // previewMintApUSD
1797
+ {
1798
+ type: "function",
1799
+ name: "previewMintApUSD",
1800
+ inputs: [
1801
+ { name: "lst", type: "address" },
1802
+ { name: "lstAmount", type: "uint256" }
1803
+ ],
1804
+ outputs: [{ name: "apUSDAmount", type: "uint256" }],
1805
+ stateMutability: "view"
1806
+ },
1807
+ // previewMintXBNB
1808
+ {
1809
+ type: "function",
1810
+ name: "previewMintXBNB",
1811
+ inputs: [
1812
+ { name: "lst", type: "address" },
1813
+ { name: "lstAmount", type: "uint256" }
1814
+ ],
1815
+ outputs: [{ name: "xBNBAmount", type: "uint256" }],
1816
+ stateMutability: "view"
1817
+ },
1818
+ // previewRedeemApUSD
1819
+ {
1820
+ type: "function",
1821
+ name: "previewRedeemApUSD",
1822
+ inputs: [
1823
+ { name: "lst", type: "address" },
1824
+ { name: "apUSDAmount", type: "uint256" }
1825
+ ],
1826
+ outputs: [{ name: "lstAmount", type: "uint256" }],
1827
+ stateMutability: "view"
1828
+ },
1829
+ // previewRedeemXBNB
1830
+ {
1831
+ type: "function",
1832
+ name: "previewRedeemXBNB",
1833
+ inputs: [
1834
+ { name: "lst", type: "address" },
1835
+ { name: "xBNBAmount", type: "uint256" }
1836
+ ],
1837
+ outputs: [{ name: "lstAmount", type: "uint256" }],
1838
+ stateMutability: "view"
1839
+ },
1780
1840
  // getUserWithdrawalIndices
1781
1841
  {
1782
1842
  type: "function",
@@ -2027,18 +2087,77 @@ var AspanRouterReadClient = class {
2027
2087
  /**
2028
2088
  * Get expected output from a swap and mint operation
2029
2089
  */
2030
- async getExpectedOutput(inputToken, inputAmount, targetLST, mintXBNB) {
2090
+ async getExpectedMintOutput(inputToken, inputAmount, targetLST, isXBNB) {
2031
2091
  const result = await this.publicClient.readContract({
2032
2092
  address: this.routerAddress,
2033
2093
  abi: RouterABI,
2034
- functionName: "getExpectedOutput",
2035
- args: [inputToken, inputAmount, targetLST, mintXBNB]
2094
+ functionName: "getExpectedMintOutput",
2095
+ args: [inputToken, inputAmount, targetLST, isXBNB]
2036
2096
  });
2037
2097
  return {
2038
2098
  expectedLST: result[0],
2039
2099
  expectedMint: result[1]
2040
2100
  };
2041
2101
  }
2102
+ /**
2103
+ * Get expected output from a redeem and swap operation
2104
+ */
2105
+ async getExpectedRedeemOutput(isXBNB, redeemAmount, lst, outputToken) {
2106
+ const result = await this.publicClient.readContract({
2107
+ address: this.routerAddress,
2108
+ abi: RouterABI,
2109
+ functionName: "getExpectedRedeemOutput",
2110
+ args: [isXBNB, redeemAmount, lst, outputToken]
2111
+ });
2112
+ return {
2113
+ expectedLST: result[0],
2114
+ expectedMint: result[1]
2115
+ };
2116
+ }
2117
+ /**
2118
+ * Preview apUSD mint output for a given LST amount
2119
+ */
2120
+ async previewMintApUSD(lst, lstAmount) {
2121
+ return this.publicClient.readContract({
2122
+ address: this.routerAddress,
2123
+ abi: RouterABI,
2124
+ functionName: "previewMintApUSD",
2125
+ args: [lst, lstAmount]
2126
+ });
2127
+ }
2128
+ /**
2129
+ * Preview xBNB mint output for a given LST amount
2130
+ */
2131
+ async previewMintXBNB(lst, lstAmount) {
2132
+ return this.publicClient.readContract({
2133
+ address: this.routerAddress,
2134
+ abi: RouterABI,
2135
+ functionName: "previewMintXBNB",
2136
+ args: [lst, lstAmount]
2137
+ });
2138
+ }
2139
+ /**
2140
+ * Preview LST output for redeeming apUSD
2141
+ */
2142
+ async previewRedeemApUSD(lst, apUSDAmount) {
2143
+ return this.publicClient.readContract({
2144
+ address: this.routerAddress,
2145
+ abi: RouterABI,
2146
+ functionName: "previewRedeemApUSD",
2147
+ args: [lst, apUSDAmount]
2148
+ });
2149
+ }
2150
+ /**
2151
+ * Preview LST output for redeeming xBNB
2152
+ */
2153
+ async previewRedeemXBNB(lst, xBNBAmount) {
2154
+ return this.publicClient.readContract({
2155
+ address: this.routerAddress,
2156
+ abi: RouterABI,
2157
+ functionName: "previewRedeemXBNB",
2158
+ args: [lst, xBNBAmount]
2159
+ });
2160
+ }
2042
2161
  /**
2043
2162
  * Get user's withdrawal request indices
2044
2163
  */
@@ -2213,7 +2332,7 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2213
2332
  functionName: "stakeAndMint",
2214
2333
  args: [
2215
2334
  params.targetLST,
2216
- params.mintXBNB,
2335
+ params.isXBNB,
2217
2336
  params.minMintOut,
2218
2337
  params.deadline
2219
2338
  ],
package/dist/index.mjs CHANGED
@@ -1497,7 +1497,7 @@ var RouterABI = [
1497
1497
  name: "stakeAndMint",
1498
1498
  inputs: [
1499
1499
  { name: "targetLST", type: "address" },
1500
- { name: "mintXBNB", type: "bool" },
1500
+ { name: "isXBNB", type: "bool" },
1501
1501
  { name: "minMintOut", type: "uint256" },
1502
1502
  { name: "deadline", type: "uint256" }
1503
1503
  ],
@@ -1722,15 +1722,15 @@ var RouterABI = [
1722
1722
  outputs: [{ name: "", type: "address" }],
1723
1723
  stateMutability: "view"
1724
1724
  },
1725
- // getExpectedOutput
1725
+ // getExpectedMintOutput
1726
1726
  {
1727
1727
  type: "function",
1728
- name: "getExpectedOutput",
1728
+ name: "getExpectedMintOutput",
1729
1729
  inputs: [
1730
1730
  { name: "inputToken", type: "address" },
1731
1731
  { name: "inputAmount", type: "uint256" },
1732
1732
  { name: "targetLST", type: "address" },
1733
- { name: "mintXBNB", type: "bool" }
1733
+ { name: "isXBNB", type: "bool" }
1734
1734
  ],
1735
1735
  outputs: [
1736
1736
  { name: "expectedLST", type: "uint256" },
@@ -1738,6 +1738,66 @@ var RouterABI = [
1738
1738
  ],
1739
1739
  stateMutability: "view"
1740
1740
  },
1741
+ // getExpectedRedeemOutput
1742
+ {
1743
+ type: "function",
1744
+ name: "getExpectedRedeemOutput",
1745
+ inputs: [
1746
+ { name: "isXBNB", type: "bool" },
1747
+ { name: "redeemAmount", type: "uint256" },
1748
+ { name: "lst", type: "address" },
1749
+ { name: "outputToken", type: "address" }
1750
+ ],
1751
+ outputs: [
1752
+ { name: "expectedLST", type: "uint256" },
1753
+ { name: "expectedOutput", type: "uint256" }
1754
+ ],
1755
+ stateMutability: "view"
1756
+ },
1757
+ // previewMintApUSD
1758
+ {
1759
+ type: "function",
1760
+ name: "previewMintApUSD",
1761
+ inputs: [
1762
+ { name: "lst", type: "address" },
1763
+ { name: "lstAmount", type: "uint256" }
1764
+ ],
1765
+ outputs: [{ name: "apUSDAmount", type: "uint256" }],
1766
+ stateMutability: "view"
1767
+ },
1768
+ // previewMintXBNB
1769
+ {
1770
+ type: "function",
1771
+ name: "previewMintXBNB",
1772
+ inputs: [
1773
+ { name: "lst", type: "address" },
1774
+ { name: "lstAmount", type: "uint256" }
1775
+ ],
1776
+ outputs: [{ name: "xBNBAmount", type: "uint256" }],
1777
+ stateMutability: "view"
1778
+ },
1779
+ // previewRedeemApUSD
1780
+ {
1781
+ type: "function",
1782
+ name: "previewRedeemApUSD",
1783
+ inputs: [
1784
+ { name: "lst", type: "address" },
1785
+ { name: "apUSDAmount", type: "uint256" }
1786
+ ],
1787
+ outputs: [{ name: "lstAmount", type: "uint256" }],
1788
+ stateMutability: "view"
1789
+ },
1790
+ // previewRedeemXBNB
1791
+ {
1792
+ type: "function",
1793
+ name: "previewRedeemXBNB",
1794
+ inputs: [
1795
+ { name: "lst", type: "address" },
1796
+ { name: "xBNBAmount", type: "uint256" }
1797
+ ],
1798
+ outputs: [{ name: "lstAmount", type: "uint256" }],
1799
+ stateMutability: "view"
1800
+ },
1741
1801
  // getUserWithdrawalIndices
1742
1802
  {
1743
1803
  type: "function",
@@ -1988,18 +2048,77 @@ var AspanRouterReadClient = class {
1988
2048
  /**
1989
2049
  * Get expected output from a swap and mint operation
1990
2050
  */
1991
- async getExpectedOutput(inputToken, inputAmount, targetLST, mintXBNB) {
2051
+ async getExpectedMintOutput(inputToken, inputAmount, targetLST, isXBNB) {
1992
2052
  const result = await this.publicClient.readContract({
1993
2053
  address: this.routerAddress,
1994
2054
  abi: RouterABI,
1995
- functionName: "getExpectedOutput",
1996
- args: [inputToken, inputAmount, targetLST, mintXBNB]
2055
+ functionName: "getExpectedMintOutput",
2056
+ args: [inputToken, inputAmount, targetLST, isXBNB]
1997
2057
  });
1998
2058
  return {
1999
2059
  expectedLST: result[0],
2000
2060
  expectedMint: result[1]
2001
2061
  };
2002
2062
  }
2063
+ /**
2064
+ * Get expected output from a redeem and swap operation
2065
+ */
2066
+ async getExpectedRedeemOutput(isXBNB, redeemAmount, lst, outputToken) {
2067
+ const result = await this.publicClient.readContract({
2068
+ address: this.routerAddress,
2069
+ abi: RouterABI,
2070
+ functionName: "getExpectedRedeemOutput",
2071
+ args: [isXBNB, redeemAmount, lst, outputToken]
2072
+ });
2073
+ return {
2074
+ expectedLST: result[0],
2075
+ expectedMint: result[1]
2076
+ };
2077
+ }
2078
+ /**
2079
+ * Preview apUSD mint output for a given LST amount
2080
+ */
2081
+ async previewMintApUSD(lst, lstAmount) {
2082
+ return this.publicClient.readContract({
2083
+ address: this.routerAddress,
2084
+ abi: RouterABI,
2085
+ functionName: "previewMintApUSD",
2086
+ args: [lst, lstAmount]
2087
+ });
2088
+ }
2089
+ /**
2090
+ * Preview xBNB mint output for a given LST amount
2091
+ */
2092
+ async previewMintXBNB(lst, lstAmount) {
2093
+ return this.publicClient.readContract({
2094
+ address: this.routerAddress,
2095
+ abi: RouterABI,
2096
+ functionName: "previewMintXBNB",
2097
+ args: [lst, lstAmount]
2098
+ });
2099
+ }
2100
+ /**
2101
+ * Preview LST output for redeeming apUSD
2102
+ */
2103
+ async previewRedeemApUSD(lst, apUSDAmount) {
2104
+ return this.publicClient.readContract({
2105
+ address: this.routerAddress,
2106
+ abi: RouterABI,
2107
+ functionName: "previewRedeemApUSD",
2108
+ args: [lst, apUSDAmount]
2109
+ });
2110
+ }
2111
+ /**
2112
+ * Preview LST output for redeeming xBNB
2113
+ */
2114
+ async previewRedeemXBNB(lst, xBNBAmount) {
2115
+ return this.publicClient.readContract({
2116
+ address: this.routerAddress,
2117
+ abi: RouterABI,
2118
+ functionName: "previewRedeemXBNB",
2119
+ args: [lst, xBNBAmount]
2120
+ });
2121
+ }
2003
2122
  /**
2004
2123
  * Get user's withdrawal request indices
2005
2124
  */
@@ -2174,7 +2293,7 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2174
2293
  functionName: "stakeAndMint",
2175
2294
  args: [
2176
2295
  params.targetLST,
2177
- params.mintXBNB,
2296
+ params.isXBNB,
2178
2297
  params.minMintOut,
2179
2298
  params.deadline
2180
2299
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspan/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "TypeScript SDK for Aspan Protocol - LST-backed stablecoin on BNB Chain",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/abi/router.ts CHANGED
@@ -82,7 +82,7 @@ export const RouterABI = [
82
82
  name: "stakeAndMint",
83
83
  inputs: [
84
84
  { name: "targetLST", type: "address" },
85
- { name: "mintXBNB", type: "bool" },
85
+ { name: "isXBNB", type: "bool" },
86
86
  { name: "minMintOut", type: "uint256" },
87
87
  { name: "deadline", type: "uint256" },
88
88
  ],
@@ -332,15 +332,15 @@ export const RouterABI = [
332
332
  stateMutability: "view",
333
333
  },
334
334
 
335
- // getExpectedOutput
335
+ // getExpectedMintOutput
336
336
  {
337
337
  type: "function",
338
- name: "getExpectedOutput",
338
+ name: "getExpectedMintOutput",
339
339
  inputs: [
340
340
  { name: "inputToken", type: "address" },
341
341
  { name: "inputAmount", type: "uint256" },
342
342
  { name: "targetLST", type: "address" },
343
- { name: "mintXBNB", type: "bool" },
343
+ { name: "isXBNB", type: "bool" },
344
344
  ],
345
345
  outputs: [
346
346
  { name: "expectedLST", type: "uint256" },
@@ -349,6 +349,71 @@ export const RouterABI = [
349
349
  stateMutability: "view",
350
350
  },
351
351
 
352
+ // getExpectedRedeemOutput
353
+ {
354
+ type: "function",
355
+ name: "getExpectedRedeemOutput",
356
+ inputs: [
357
+ { name: "isXBNB", type: "bool" },
358
+ { name: "redeemAmount", type: "uint256" },
359
+ { name: "lst", type: "address" },
360
+ { name: "outputToken", type: "address" },
361
+ ],
362
+ outputs: [
363
+ { name: "expectedLST", type: "uint256" },
364
+ { name: "expectedOutput", type: "uint256" },
365
+ ],
366
+ stateMutability: "view",
367
+ },
368
+
369
+ // previewMintApUSD
370
+ {
371
+ type: "function",
372
+ name: "previewMintApUSD",
373
+ inputs: [
374
+ { name: "lst", type: "address" },
375
+ { name: "lstAmount", type: "uint256" },
376
+ ],
377
+ outputs: [{ name: "apUSDAmount", type: "uint256" }],
378
+ stateMutability: "view",
379
+ },
380
+
381
+ // previewMintXBNB
382
+ {
383
+ type: "function",
384
+ name: "previewMintXBNB",
385
+ inputs: [
386
+ { name: "lst", type: "address" },
387
+ { name: "lstAmount", type: "uint256" },
388
+ ],
389
+ outputs: [{ name: "xBNBAmount", type: "uint256" }],
390
+ stateMutability: "view",
391
+ },
392
+
393
+ // previewRedeemApUSD
394
+ {
395
+ type: "function",
396
+ name: "previewRedeemApUSD",
397
+ inputs: [
398
+ { name: "lst", type: "address" },
399
+ { name: "apUSDAmount", type: "uint256" },
400
+ ],
401
+ outputs: [{ name: "lstAmount", type: "uint256" }],
402
+ stateMutability: "view",
403
+ },
404
+
405
+ // previewRedeemXBNB
406
+ {
407
+ type: "function",
408
+ name: "previewRedeemXBNB",
409
+ inputs: [
410
+ { name: "lst", type: "address" },
411
+ { name: "xBNBAmount", type: "uint256" },
412
+ ],
413
+ outputs: [{ name: "lstAmount", type: "uint256" }],
414
+ stateMutability: "view",
415
+ },
416
+
352
417
  // getUserWithdrawalIndices
353
418
  {
354
419
  type: "function",
package/src/router.ts CHANGED
@@ -121,17 +121,17 @@ export class AspanRouterReadClient {
121
121
  /**
122
122
  * Get expected output from a swap and mint operation
123
123
  */
124
- async getExpectedOutput(
124
+ async getExpectedMintOutput(
125
125
  inputToken: Address,
126
126
  inputAmount: bigint,
127
127
  targetLST: Address,
128
- mintXBNB: boolean
128
+ isXBNB: boolean
129
129
  ): Promise<ExpectedOutput> {
130
130
  const result = await this.publicClient.readContract({
131
131
  address: this.routerAddress,
132
132
  abi: RouterABI,
133
- functionName: "getExpectedOutput",
134
- args: [inputToken, inputAmount, targetLST, mintXBNB],
133
+ functionName: "getExpectedMintOutput",
134
+ args: [inputToken, inputAmount, targetLST, isXBNB],
135
135
  });
136
136
 
137
137
  return {
@@ -140,6 +140,76 @@ export class AspanRouterReadClient {
140
140
  };
141
141
  }
142
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
+ /**
166
+ * Preview apUSD mint output for a given LST amount
167
+ */
168
+ async previewMintApUSD(lst: Address, lstAmount: bigint): Promise<bigint> {
169
+ return this.publicClient.readContract({
170
+ address: this.routerAddress,
171
+ abi: RouterABI,
172
+ functionName: "previewMintApUSD",
173
+ args: [lst, lstAmount],
174
+ });
175
+ }
176
+
177
+ /**
178
+ * Preview xBNB mint output for a given LST amount
179
+ */
180
+ async previewMintXBNB(lst: Address, lstAmount: bigint): Promise<bigint> {
181
+ return this.publicClient.readContract({
182
+ address: this.routerAddress,
183
+ abi: RouterABI,
184
+ functionName: "previewMintXBNB",
185
+ args: [lst, lstAmount],
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Preview LST output for redeeming apUSD
191
+ */
192
+ async previewRedeemApUSD(lst: Address, apUSDAmount: bigint): Promise<bigint> {
193
+ return this.publicClient.readContract({
194
+ address: this.routerAddress,
195
+ abi: RouterABI,
196
+ functionName: "previewRedeemApUSD",
197
+ args: [lst, apUSDAmount],
198
+ });
199
+ }
200
+
201
+ /**
202
+ * Preview LST output for redeeming xBNB
203
+ */
204
+ async previewRedeemXBNB(lst: Address, xBNBAmount: bigint): Promise<bigint> {
205
+ return this.publicClient.readContract({
206
+ address: this.routerAddress,
207
+ abi: RouterABI,
208
+ functionName: "previewRedeemXBNB",
209
+ args: [lst, xBNBAmount],
210
+ });
211
+ }
212
+
143
213
  /**
144
214
  * Get user's withdrawal request indices
145
215
  */
@@ -347,7 +417,7 @@ export class AspanRouterClient extends AspanRouterReadClient {
347
417
  functionName: "stakeAndMint",
348
418
  args: [
349
419
  params.targetLST,
350
- params.mintXBNB,
420
+ params.isXBNB,
351
421
  params.minMintOut,
352
422
  params.deadline,
353
423
  ],
package/src/types.ts CHANGED
@@ -285,7 +285,7 @@ export interface StakeAndMintParams {
285
285
  /** Target LST (slisBNB, asBNB, wclisBNB) */
286
286
  targetLST: Address;
287
287
  /** true = mint xBNB, false = mint apUSD */
288
- mintXBNB: boolean;
288
+ isXBNB: boolean;
289
289
  /** Minimum output to receive */
290
290
  minMintOut: bigint;
291
291
  /** Transaction deadline timestamp */