@rhea-finance/cross-chain-sdk 0.1.11 → 0.1.13

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
@@ -915,6 +915,154 @@ if (res.status === "success") {
915
915
  }
916
916
  ```
917
917
 
918
+ ### LSD Intents Supply and Withdraw
919
+
920
+ The LSD module prepares the two-leg Intents route used by the LSD page in the demo project:
921
+
922
+ - Supply: BSC USDT -> NEAR USDT -> LSD -> BSC lsdUSDT
923
+ - Withdraw: BSC lsdUSDT -> NEAR LSD -> USDT -> BSC USDT
924
+
925
+ The SDK prepares quotes and transfer data, but it does not send EVM wallet transactions. Your app should use its own wallet integration to transfer the returned token amount to the returned `depositAddress`.
926
+
927
+ ```typescript
928
+ import {
929
+ BSC_CHAIN_ID,
930
+ calculateLsdFromUsdt,
931
+ calculateUsdtFromLsd,
932
+ getLsdBalances,
933
+ pollLsdIntentsTransactionStatuses,
934
+ prepareLsdSupplyByIntents,
935
+ prepareLsdWithdrawByIntents,
936
+ quoteLsdSupplyByIntents,
937
+ quoteLsdWithdrawByIntents,
938
+ } from "@rhea-finance/cross-chain-sdk";
939
+
940
+ // This is app-side wallet code, not provided by the SDK.
941
+ async function transferToken(params: {
942
+ tokenAddress: string;
943
+ depositAddress: string;
944
+ chain: "bsc";
945
+ amount: string;
946
+ }) {
947
+ // Example:
948
+ // await erc20Contract.transfer(params.depositAddress, params.amount);
949
+ }
950
+
951
+ const accountAddress = "0x...";
952
+
953
+ // Optional: pass your own BSC RPC if the default RPC is unstable.
954
+ const balances = await getLsdBalances({
955
+ accountAddress,
956
+ rpcUrl: "https://your-bsc-rpc.example",
957
+ });
958
+ console.log(balances.usdt);
959
+ console.log(balances.lsdUsdt);
960
+
961
+ // Exchange conversion helpers return both readable and raw values.
962
+ const lsdFromUsdt = await calculateLsdFromUsdt("100");
963
+ console.log(lsdFromUsdt.readableAmount); // readable lsdUSDT amount for display
964
+ console.log(lsdFromUsdt.amount); // raw lsdUSDT amount with token precision
965
+
966
+ const usdtFromLsd = await calculateUsdtFromLsd("50");
967
+ console.log(usdtFromLsd.readableAmount); // readable USDT amount for display
968
+ console.log(usdtFromLsd.amount); // raw NEAR USDT amount for Intents quote
969
+
970
+ // Quote supply. Amounts are human-readable strings.
971
+ const supplyQuote = await quoteLsdSupplyByIntents({
972
+ accountAddress,
973
+ amount: "100",
974
+ });
975
+ console.log(supplyQuote.estimatedReceive);
976
+ console.log(supplyQuote.bridgeFeeUsd);
977
+
978
+ // Prepare supply transfer data.
979
+ const preparedSupply = await prepareLsdSupplyByIntents({
980
+ accountAddress,
981
+ amount: "100",
982
+ onStatusChange(stage) {
983
+ console.log("Supply prepare stage:", stage);
984
+ },
985
+ });
986
+
987
+ if (preparedSupply.status !== "success" || !preparedSupply.transferData) {
988
+ throw new Error(preparedSupply.message || "Failed to prepare LSD supply");
989
+ }
990
+
991
+ await transferToken({
992
+ tokenAddress: preparedSupply.transferData.tokenAddress,
993
+ depositAddress: preparedSupply.transferData.depositAddress,
994
+ chain: preparedSupply.transferData.chain,
995
+ amount: preparedSupply.transferData.amount,
996
+ });
997
+
998
+ if (!preparedSupply.intentsDepositAddresses) {
999
+ throw new Error("Missing Intents deposit addresses");
1000
+ }
1001
+
1002
+ const supplyStatuses = await pollLsdIntentsTransactionStatuses({
1003
+ originDepositAddress:
1004
+ preparedSupply.intentsDepositAddresses.originDepositAddress,
1005
+ returnDepositAddress:
1006
+ preparedSupply.intentsDepositAddresses.returnDepositAddress,
1007
+ });
1008
+
1009
+ if (
1010
+ supplyStatuses.origin.status !== "success" ||
1011
+ supplyStatuses.return.status !== "success"
1012
+ ) {
1013
+ throw new Error(
1014
+ `LSD supply failed: origin=${supplyStatuses.origin.status}, return=${supplyStatuses.return.status}`
1015
+ );
1016
+ }
1017
+
1018
+ // Quote withdraw.
1019
+ const withdrawQuote = await quoteLsdWithdrawByIntents({
1020
+ accountAddress,
1021
+ amount: "50",
1022
+ });
1023
+ console.log(withdrawQuote.estimatedReceive);
1024
+ console.log(withdrawQuote.bridgeFeeUsd);
1025
+
1026
+ // Prepare withdraw transfer data.
1027
+ const preparedWithdraw = await prepareLsdWithdrawByIntents({
1028
+ accountAddress,
1029
+ amount: "50",
1030
+ });
1031
+
1032
+ if (preparedWithdraw.status !== "success" || !preparedWithdraw.transferData) {
1033
+ throw new Error(
1034
+ preparedWithdraw.message || "Failed to prepare LSD withdraw"
1035
+ );
1036
+ }
1037
+
1038
+ await transferToken({
1039
+ tokenAddress: preparedWithdraw.transferData.tokenAddress,
1040
+ depositAddress: preparedWithdraw.transferData.depositAddress,
1041
+ chain: preparedWithdraw.transferData.chain,
1042
+ amount: preparedWithdraw.transferData.amount,
1043
+ });
1044
+
1045
+ if (!preparedWithdraw.intentsDepositAddresses) {
1046
+ throw new Error("Missing Intents deposit addresses");
1047
+ }
1048
+
1049
+ const withdrawStatuses = await pollLsdIntentsTransactionStatuses({
1050
+ originDepositAddress:
1051
+ preparedWithdraw.intentsDepositAddresses.originDepositAddress,
1052
+ returnDepositAddress:
1053
+ preparedWithdraw.intentsDepositAddresses.returnDepositAddress,
1054
+ });
1055
+
1056
+ if (
1057
+ withdrawStatuses.origin.status !== "success" ||
1058
+ withdrawStatuses.return.status !== "success"
1059
+ ) {
1060
+ throw new Error(
1061
+ `LSD withdraw failed: origin=${withdrawStatuses.origin.status}, return=${withdrawStatuses.return.status}`
1062
+ );
1063
+ }
1064
+ ```
1065
+
918
1066
  ## Core API
919
1067
 
920
1068
  ### Actions