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

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
@@ -930,6 +930,7 @@ import {
930
930
  calculateLsdFromUsdt,
931
931
  calculateUsdtFromLsd,
932
932
  getLsdBalances,
933
+ getLsdIntentsOrderHistory,
933
934
  pollLsdIntentsTransactionStatuses,
934
935
  prepareLsdSupplyByIntents,
935
936
  prepareLsdWithdrawByIntents,
@@ -958,6 +959,20 @@ const balances = await getLsdBalances({
958
959
  console.log(balances.usdt);
959
960
  console.log(balances.lsdUsdt);
960
961
 
962
+ // Query LSD intents order history for the current wallet.
963
+ // The SDK returns a lightweight record_list with:
964
+ // timestamp
965
+ // status
966
+ // quoteRequest.originAsset / destinationAsset / recipient / refundTo / customRecipientMsg
967
+ // quote (all fields)
968
+ const history = await getLsdIntentsOrderHistory({
969
+ accountId: accountAddress,
970
+ pageSize: 10,
971
+ });
972
+ console.log(history.total_size);
973
+ console.log(history.record_list[0]?.status);
974
+ console.log(history.record_list[0]?.quote.depositAddress);
975
+
961
976
  // Exchange conversion helpers return both readable and raw values.
962
977
  const lsdFromUsdt = await calculateLsdFromUsdt("100");
963
978
  console.log(lsdFromUsdt.readableAmount); // readable lsdUSDT amount for display
package/dist/index.cjs CHANGED
@@ -18138,25 +18138,52 @@ async function get_tx_id(receipt_id) {
18138
18138
  return {};
18139
18139
  }
18140
18140
  }
18141
+ var INTENTS_ORDER_API_URL = `${indexUrl}/api/1click`;
18142
+ function buildIntentsQuoteRequest(params) {
18143
+ return {
18144
+ originAsset: params?.originAsset,
18145
+ destinationAsset: params?.destinationAsset,
18146
+ amount: params?.amount,
18147
+ refundTo: params?.refundTo,
18148
+ recipient: params?.recipient,
18149
+ customRecipientMsg: params?.customRecipientMsg,
18150
+ dry: params?.dry || false,
18151
+ swapType: params.isReverse ? "EXACT_OUTPUT" : "EXACT_INPUT",
18152
+ refundType: "ORIGIN_CHAIN",
18153
+ recipientType: "DESTINATION_CHAIN",
18154
+ depositType: "ORIGIN_CHAIN",
18155
+ deadline: new Date(Date.now() + 1 * 60 * 60 * 1e3).toISOString(),
18156
+ referral: "rhea",
18157
+ quoteWaitingTimeMs: 3e3,
18158
+ slippageTolerance: typeof params.slippageTolerance == "number" ? params.slippageTolerance : 50
18159
+ };
18160
+ }
18161
+ function normalizeIntentsQuoteResponse(response) {
18162
+ const quote = response?.quote;
18163
+ if (quote) {
18164
+ const feeAmountBig = new Big3__default.default(quote?.amountInFormatted || 0).minus(
18165
+ quote?.amountOutFormatted || 0
18166
+ );
18167
+ const feeUsdBig = new Big3__default.default(quote?.amountInUsd || 0).minus(
18168
+ quote?.amountOutUsd || 0
18169
+ );
18170
+ return {
18171
+ quoteStatus: "success",
18172
+ quoteSuccessResult: response,
18173
+ quoteFeeData: {
18174
+ feeAmount: feeAmountBig.gt(0) ? feeAmountBig.toFixed() : "0",
18175
+ feeUsd: feeUsdBig.gt(0) ? feeUsdBig.toFixed() : "0"
18176
+ }
18177
+ };
18178
+ }
18179
+ return {
18180
+ quoteStatus: "error",
18181
+ message: response?.message || response?.error
18182
+ };
18183
+ }
18141
18184
  async function fetchIntentsQuotation(params) {
18142
18185
  try {
18143
- const res_params = {
18144
- originAsset: params?.originAsset,
18145
- destinationAsset: params?.destinationAsset,
18146
- amount: params?.amount,
18147
- refundTo: params?.refundTo,
18148
- recipient: params?.recipient,
18149
- customRecipientMsg: params?.customRecipientMsg,
18150
- dry: params?.dry || false,
18151
- swapType: params.isReverse ? "EXACT_OUTPUT" : "EXACT_INPUT",
18152
- refundType: "ORIGIN_CHAIN",
18153
- recipientType: "DESTINATION_CHAIN",
18154
- depositType: "ORIGIN_CHAIN",
18155
- deadline: new Date(Date.now() + 1 * 60 * 60 * 1e3).toISOString(),
18156
- referral: "rhea",
18157
- quoteWaitingTimeMs: 3e3,
18158
- slippageTolerance: typeof params.slippageTolerance == "number" ? params.slippageTolerance : 50
18159
- };
18186
+ const res_params = buildIntentsQuoteRequest(params);
18160
18187
  const response = await fetch(`${oneClickUrl}/quote`, {
18161
18188
  method: "POST",
18162
18189
  headers: {
@@ -18166,28 +18193,27 @@ async function fetchIntentsQuotation(params) {
18166
18193
  }).then((res) => {
18167
18194
  return res.json();
18168
18195
  });
18169
- const quote = response?.quote;
18170
- if (quote) {
18171
- const feeAmountBig = new Big3__default.default(quote?.amountInFormatted || 0).minus(
18172
- quote?.amountOutFormatted || 0
18173
- );
18174
- const feeUsdBig = new Big3__default.default(quote?.amountInUsd || 0).minus(
18175
- quote?.amountOutUsd || 0
18176
- );
18177
- return {
18178
- quoteStatus: "success",
18179
- quoteSuccessResult: response,
18180
- quoteFeeData: {
18181
- feeAmount: feeAmountBig.gt(0) ? feeAmountBig.toFixed() : "0",
18182
- feeUsd: feeUsdBig.gt(0) ? feeUsdBig.toFixed() : "0"
18183
- }
18184
- };
18185
- } else {
18186
- return {
18187
- quoteStatus: "error",
18188
- message: response?.message
18189
- };
18190
- }
18196
+ return normalizeIntentsQuoteResponse(response);
18197
+ } catch (error) {
18198
+ return {
18199
+ quoteStatus: "error",
18200
+ message: error?.message || error?.error
18201
+ };
18202
+ }
18203
+ }
18204
+ async function fetchIntentsCreateOrder(params) {
18205
+ try {
18206
+ const res_params = buildIntentsQuoteRequest(params);
18207
+ const response = await fetch(`${INTENTS_ORDER_API_URL}/create-order`, {
18208
+ method: "POST",
18209
+ headers: {
18210
+ "Content-type": "application/json; charset=UTF-8"
18211
+ },
18212
+ body: JSON.stringify(res_params)
18213
+ }).then((res) => {
18214
+ return res.json();
18215
+ });
18216
+ return normalizeIntentsQuoteResponse(response);
18191
18217
  } catch (error) {
18192
18218
  return {
18193
18219
  quoteStatus: "error",
@@ -18195,6 +18221,34 @@ async function fetchIntentsQuotation(params) {
18195
18221
  };
18196
18222
  }
18197
18223
  }
18224
+ async function fetchIntentsOrders(params) {
18225
+ try {
18226
+ const searchParams = new URLSearchParams({
18227
+ refund_to: params.refundTo
18228
+ });
18229
+ if (typeof params.pageNumber === "number") {
18230
+ searchParams.set("page_number", String(params.pageNumber));
18231
+ }
18232
+ if (typeof params.pageSize === "number") {
18233
+ searchParams.set("page_size", String(params.pageSize));
18234
+ }
18235
+ const response = await fetch(
18236
+ `${INTENTS_ORDER_API_URL}/orders?${searchParams.toString()}`,
18237
+ {
18238
+ method: "GET",
18239
+ headers: {
18240
+ "Content-type": "application/json; charset=UTF-8"
18241
+ }
18242
+ }
18243
+ ).then((res) => {
18244
+ return res.json();
18245
+ });
18246
+ return response;
18247
+ } catch (error) {
18248
+ console.error("Error fetchIntentsOrders:", error);
18249
+ return null;
18250
+ }
18251
+ }
18198
18252
  async function fetchIntentsTransactionStatus(depositAddress) {
18199
18253
  try {
18200
18254
  const response = await fetch(
@@ -21229,6 +21283,30 @@ async function quoteNearUsdtToBscUsdt(params) {
21229
21283
  slippageTolerance: params.slippageTolerance
21230
21284
  });
21231
21285
  }
21286
+ async function createOrderBscUsdtToNearUsdt(params) {
21287
+ return fetchIntentsCreateOrder({
21288
+ originAsset: BSC_USDT_INTENTS_ASSET_ID,
21289
+ destinationAsset: NEAR_USDT_INTENTS_ASSET_ID,
21290
+ amount: params.amount,
21291
+ refundTo: params.refundTo,
21292
+ recipient: params.recipient,
21293
+ customRecipientMsg: params.customRecipientMsg,
21294
+ dry: params.dry,
21295
+ slippageTolerance: params.slippageTolerance
21296
+ });
21297
+ }
21298
+ async function createOrderBscLsdToNearLsd(params) {
21299
+ return fetchIntentsCreateOrder({
21300
+ originAsset: BSC_NRUSDT_INTENTS_ASSET_ID,
21301
+ destinationAsset: NEAR_NRUSDT_INTENTS_ASSET_ID,
21302
+ amount: params.amount,
21303
+ refundTo: params.refundTo,
21304
+ recipient: params.recipient,
21305
+ customRecipientMsg: params.customRecipientMsg,
21306
+ dry: params.dry,
21307
+ slippageTolerance: params.slippageTolerance
21308
+ });
21309
+ }
21232
21310
  function buildPreparedTransfer(params) {
21233
21311
  return {
21234
21312
  chain: "bsc",
@@ -21355,7 +21433,7 @@ async function prepareLsdSupplyByIntents(params) {
21355
21433
  secondQuote,
21356
21434
  "LSD supply return"
21357
21435
  );
21358
- const finalQuote = await quoteBscUsdtToNearUsdt({
21436
+ const finalQuote = await createOrderBscUsdtToNearUsdt({
21359
21437
  amount: supplyAmountRaw,
21360
21438
  refundTo: params.accountAddress,
21361
21439
  recipient: LSD_CONTRACT_ID,
@@ -21441,7 +21519,7 @@ async function prepareLsdWithdrawByIntents(params) {
21441
21519
  secondQuote,
21442
21520
  "LSD withdraw return"
21443
21521
  );
21444
- const finalQuote = await quoteBscLsdToNearLsd({
21522
+ const finalQuote = await createOrderBscLsdToNearLsd({
21445
21523
  amount: withdrawAmountRaw,
21446
21524
  refundTo: params.accountAddress,
21447
21525
  recipient: LSD_CONTRACT_ID,
@@ -21533,6 +21611,38 @@ async function pollLsdIntentsTransactionStatuses(params) {
21533
21611
  }
21534
21612
  };
21535
21613
  }
21614
+ async function getLsdIntentsOrderHistory(params) {
21615
+ if (!params.accountId) {
21616
+ throw new Error("accountId is required");
21617
+ }
21618
+ const response = await fetchIntentsOrders({
21619
+ refundTo: params.accountId,
21620
+ pageNumber: params.pageNumber,
21621
+ pageSize: params.pageSize
21622
+ });
21623
+ if (!response) {
21624
+ throw new Error("Failed to fetch LSD intents order history");
21625
+ }
21626
+ const recordList = Array.isArray(response.record_list) ? response.record_list.map((record) => ({
21627
+ timestamp: record?.quote_response?.timestamp,
21628
+ status: record?.status || "",
21629
+ quoteRequest: {
21630
+ originAsset: record?.quote_response?.quoteRequest?.originAsset || "",
21631
+ destinationAsset: record?.quote_response?.quoteRequest?.destinationAsset || "",
21632
+ recipient: record?.quote_response?.quoteRequest?.recipient || "",
21633
+ refundTo: record?.quote_response?.quoteRequest?.refundTo || "",
21634
+ customRecipientMsg: record?.quote_response?.quoteRequest?.customRecipientMsg || ""
21635
+ },
21636
+ quote: record?.quote_response?.quote
21637
+ })) : [];
21638
+ return {
21639
+ page_number: response.page_number || 1,
21640
+ page_size: response.page_size || recordList.length,
21641
+ total_page: response.total_page || 0,
21642
+ total_size: response.total_size || recordList.length,
21643
+ record_list: recordList
21644
+ };
21645
+ }
21536
21646
 
21537
21647
  // src/lsd/service.ts
21538
21648
  init_polyfills();
@@ -21685,6 +21795,8 @@ exports.decimalMax = decimalMax;
21685
21795
  exports.decimalMin = decimalMin;
21686
21796
  exports.expandToken = expandToken;
21687
21797
  exports.expandTokenDecimal = expandTokenDecimal;
21798
+ exports.fetchIntentsCreateOrder = fetchIntentsCreateOrder;
21799
+ exports.fetchIntentsOrders = fetchIntentsOrders;
21688
21800
  exports.fetchIntentsQuotation = fetchIntentsQuotation;
21689
21801
  exports.fetchIntentsTokens = fetchIntentsTokens;
21690
21802
  exports.fetchIntentsTransactionStatus = fetchIntentsTransactionStatus;
@@ -21713,6 +21825,7 @@ exports.getCreateMcaFeePaged = getCreateMcaFeePaged;
21713
21825
  exports.getFarmDetailsOfAsset = getFarmDetailsOfAsset;
21714
21826
  exports.getListWalletsByMca = getListWalletsByMca;
21715
21827
  exports.getLsdBalances = getLsdBalances;
21828
+ exports.getLsdIntentsOrderHistory = getLsdIntentsOrderHistory;
21716
21829
  exports.getLsdMetadata = getLsdMetadata;
21717
21830
  exports.getLsdTotalSupply = getLsdTotalSupply;
21718
21831
  exports.getMcaByWallet = getMcaByWallet;