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

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,56 +18138,65 @@ 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: {
18163
- "Content-type": "application/json; charset=UTF-8"
18190
+ "Content-type": "application/json; charset=UTF-8",
18191
+ ...params.authorization ? {
18192
+ Authorization: params.authorization
18193
+ } : {}
18164
18194
  },
18165
18195
  body: JSON.stringify(res_params)
18166
18196
  }).then((res) => {
18167
18197
  return res.json();
18168
18198
  });
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
- }
18199
+ return normalizeIntentsQuoteResponse(response);
18191
18200
  } catch (error) {
18192
18201
  return {
18193
18202
  quoteStatus: "error",
@@ -18195,6 +18204,55 @@ async function fetchIntentsQuotation(params) {
18195
18204
  };
18196
18205
  }
18197
18206
  }
18207
+ async function fetchIntentsCreateOrder(params) {
18208
+ try {
18209
+ const res_params = buildIntentsQuoteRequest(params);
18210
+ const response = await fetch(`${INTENTS_ORDER_API_URL}/create-order`, {
18211
+ method: "POST",
18212
+ headers: {
18213
+ "Content-type": "application/json; charset=UTF-8"
18214
+ },
18215
+ body: JSON.stringify(res_params)
18216
+ }).then((res) => {
18217
+ return res.json();
18218
+ });
18219
+ const normalizedResponse = normalizeIntentsQuoteResponse(response);
18220
+ if (normalizedResponse.quoteStatus === "success") {
18221
+ return normalizedResponse;
18222
+ }
18223
+ return fetchIntentsQuotation(params);
18224
+ } catch (error) {
18225
+ return fetchIntentsQuotation(params);
18226
+ }
18227
+ }
18228
+ async function fetchIntentsOrders(params) {
18229
+ try {
18230
+ const searchParams = new URLSearchParams({
18231
+ refund_to: params.refundTo
18232
+ });
18233
+ if (typeof params.pageNumber === "number") {
18234
+ searchParams.set("page_number", String(params.pageNumber));
18235
+ }
18236
+ if (typeof params.pageSize === "number") {
18237
+ searchParams.set("page_size", String(params.pageSize));
18238
+ }
18239
+ const response = await fetch(
18240
+ `${INTENTS_ORDER_API_URL}/orders?${searchParams.toString()}`,
18241
+ {
18242
+ method: "GET",
18243
+ headers: {
18244
+ "Content-type": "application/json; charset=UTF-8"
18245
+ }
18246
+ }
18247
+ ).then((res) => {
18248
+ return res.json();
18249
+ });
18250
+ return response;
18251
+ } catch (error) {
18252
+ console.error("Error fetchIntentsOrders:", error);
18253
+ return null;
18254
+ }
18255
+ }
18198
18256
  async function fetchIntentsTransactionStatus(depositAddress) {
18199
18257
  try {
18200
18258
  const response = await fetch(
@@ -20184,7 +20242,8 @@ async function intentsQuotation({
20184
20242
  customRecipientMsg,
20185
20243
  isReverse,
20186
20244
  dry,
20187
- slippageTolerance
20245
+ slippageTolerance,
20246
+ authorization
20188
20247
  }) {
20189
20248
  const res_quote = await fetchIntentsQuotation({
20190
20249
  originAsset,
@@ -20195,6 +20254,7 @@ async function intentsQuotation({
20195
20254
  isReverse,
20196
20255
  dry,
20197
20256
  slippageTolerance,
20257
+ authorization,
20198
20258
  ...customRecipientMsg ? { customRecipientMsg } : {}
20199
20259
  });
20200
20260
  return res_quote;
@@ -21082,6 +21142,7 @@ var BSC_USDT_INTENTS_ASSET_ID = "nep245:v2_1.omni.hot.tg:56_2CMMyVTGZkeyNZTSvS5s
21082
21142
  var NEAR_USDT_INTENTS_ASSET_ID = "nep141:usdt.tether-token.near";
21083
21143
  var BSC_NRUSDT_INTENTS_ASSET_ID = "1cs_v1:bsc:bep20:0x5382555840ef9f54ef6d3ee5da60f12bcabf4b87";
21084
21144
  var NEAR_NRUSDT_INTENTS_ASSET_ID = "nep141:lsd-usdt.rhealab.near";
21145
+ var LSD_INTENTS_QUOTE_AUTHORIZATION = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjIwMjUtMDEtMTItdjEifQ.eyJ2IjoxLCJrZXlfdHlwZSI6ImRpc3RyaWJ1dGlvbl9jaGFubmVsIiwicGFydG5lcl9pZCI6InJoZWEiLCJpYXQiOjE3NzAwMjQ0MjQsImV4cCI6MTgwMTU2MDQyNH0.EAKZgGKPVLJkf1gbPAETZQ_sz20sTSg-QHbWBKWJWELMLQqQpA0Tbe8QJU7FuoQZRnor6osDEL-Wv6wWFxM0nWGKtU0ov7k5QhYsEQe-MhR-kEHA9YNz2Wm9YHCbf2fhTt7HJqN9lRTpfMqB67QaA9muGjYx8J50wh0plcfD-FVaOTHyyv4HNiQM_GTlxLwE9yHgrdBYh-okySMFX2Ok565vOe0nqjl2naJ86qatJyVrOUovGSbZJ1gO-NLfFafz2zjmTcIZsZOA5qGoiqEfg48ur5ISg-F94rNgdWU-PlIJLsCD-bEstEsUF8wQwxdQPbmNMFO4F7CCD7OmwZ5mLw";
21085
21146
 
21086
21147
  // src/lsd/intents.ts
21087
21148
  init_polyfills();
@@ -21190,7 +21251,8 @@ async function quoteBscUsdtToNearUsdt(params) {
21190
21251
  recipient: params.recipient,
21191
21252
  customRecipientMsg: params.customRecipientMsg,
21192
21253
  dry: params.dry,
21193
- slippageTolerance: params.slippageTolerance
21254
+ slippageTolerance: params.slippageTolerance,
21255
+ authorization: LSD_INTENTS_QUOTE_AUTHORIZATION
21194
21256
  });
21195
21257
  }
21196
21258
  async function quoteNearLsdToBscLsd(params) {
@@ -21202,7 +21264,8 @@ async function quoteNearLsdToBscLsd(params) {
21202
21264
  recipient: params.recipient,
21203
21265
  customRecipientMsg: params.customRecipientMsg,
21204
21266
  dry: params.dry,
21205
- slippageTolerance: params.slippageTolerance
21267
+ slippageTolerance: params.slippageTolerance,
21268
+ authorization: LSD_INTENTS_QUOTE_AUTHORIZATION
21206
21269
  });
21207
21270
  }
21208
21271
  async function quoteBscLsdToNearLsd(params) {
@@ -21214,7 +21277,8 @@ async function quoteBscLsdToNearLsd(params) {
21214
21277
  recipient: params.recipient,
21215
21278
  customRecipientMsg: params.customRecipientMsg,
21216
21279
  dry: params.dry,
21217
- slippageTolerance: params.slippageTolerance
21280
+ slippageTolerance: params.slippageTolerance,
21281
+ authorization: LSD_INTENTS_QUOTE_AUTHORIZATION
21218
21282
  });
21219
21283
  }
21220
21284
  async function quoteNearUsdtToBscUsdt(params) {
@@ -21226,6 +21290,31 @@ async function quoteNearUsdtToBscUsdt(params) {
21226
21290
  recipient: params.recipient,
21227
21291
  customRecipientMsg: params.customRecipientMsg,
21228
21292
  dry: params.dry,
21293
+ slippageTolerance: params.slippageTolerance,
21294
+ authorization: LSD_INTENTS_QUOTE_AUTHORIZATION
21295
+ });
21296
+ }
21297
+ async function createOrderBscUsdtToNearUsdt(params) {
21298
+ return fetchIntentsCreateOrder({
21299
+ originAsset: BSC_USDT_INTENTS_ASSET_ID,
21300
+ destinationAsset: NEAR_USDT_INTENTS_ASSET_ID,
21301
+ amount: params.amount,
21302
+ refundTo: params.refundTo,
21303
+ recipient: params.recipient,
21304
+ customRecipientMsg: params.customRecipientMsg,
21305
+ dry: params.dry,
21306
+ slippageTolerance: params.slippageTolerance
21307
+ });
21308
+ }
21309
+ async function createOrderBscLsdToNearLsd(params) {
21310
+ return fetchIntentsCreateOrder({
21311
+ originAsset: BSC_NRUSDT_INTENTS_ASSET_ID,
21312
+ destinationAsset: NEAR_NRUSDT_INTENTS_ASSET_ID,
21313
+ amount: params.amount,
21314
+ refundTo: params.refundTo,
21315
+ recipient: params.recipient,
21316
+ customRecipientMsg: params.customRecipientMsg,
21317
+ dry: params.dry,
21229
21318
  slippageTolerance: params.slippageTolerance
21230
21319
  });
21231
21320
  }
@@ -21355,7 +21444,7 @@ async function prepareLsdSupplyByIntents(params) {
21355
21444
  secondQuote,
21356
21445
  "LSD supply return"
21357
21446
  );
21358
- const finalQuote = await quoteBscUsdtToNearUsdt({
21447
+ const finalQuote = await createOrderBscUsdtToNearUsdt({
21359
21448
  amount: supplyAmountRaw,
21360
21449
  refundTo: params.accountAddress,
21361
21450
  recipient: LSD_CONTRACT_ID,
@@ -21441,7 +21530,7 @@ async function prepareLsdWithdrawByIntents(params) {
21441
21530
  secondQuote,
21442
21531
  "LSD withdraw return"
21443
21532
  );
21444
- const finalQuote = await quoteBscLsdToNearLsd({
21533
+ const finalQuote = await createOrderBscLsdToNearLsd({
21445
21534
  amount: withdrawAmountRaw,
21446
21535
  refundTo: params.accountAddress,
21447
21536
  recipient: LSD_CONTRACT_ID,
@@ -21533,6 +21622,38 @@ async function pollLsdIntentsTransactionStatuses(params) {
21533
21622
  }
21534
21623
  };
21535
21624
  }
21625
+ async function getLsdIntentsOrderHistory(params) {
21626
+ if (!params.accountId) {
21627
+ throw new Error("accountId is required");
21628
+ }
21629
+ const response = await fetchIntentsOrders({
21630
+ refundTo: params.accountId,
21631
+ pageNumber: params.pageNumber,
21632
+ pageSize: params.pageSize
21633
+ });
21634
+ if (!response) {
21635
+ throw new Error("Failed to fetch LSD intents order history");
21636
+ }
21637
+ const recordList = Array.isArray(response.record_list) ? response.record_list.map((record) => ({
21638
+ timestamp: record?.quote_response?.timestamp,
21639
+ status: record?.status || "",
21640
+ quoteRequest: {
21641
+ originAsset: record?.quote_response?.quoteRequest?.originAsset || "",
21642
+ destinationAsset: record?.quote_response?.quoteRequest?.destinationAsset || "",
21643
+ recipient: record?.quote_response?.quoteRequest?.recipient || "",
21644
+ refundTo: record?.quote_response?.quoteRequest?.refundTo || "",
21645
+ customRecipientMsg: record?.quote_response?.quoteRequest?.customRecipientMsg || ""
21646
+ },
21647
+ quote: record?.quote_response?.quote
21648
+ })) : [];
21649
+ return {
21650
+ page_number: response.page_number || 1,
21651
+ page_size: response.page_size || recordList.length,
21652
+ total_page: response.total_page || 0,
21653
+ total_size: response.total_size || recordList.length,
21654
+ record_list: recordList
21655
+ };
21656
+ }
21536
21657
 
21537
21658
  // src/lsd/service.ts
21538
21659
  init_polyfills();
@@ -21661,6 +21782,7 @@ exports.BURROW_CONTRACT_ID = BURROW_CONTRACT_ID;
21661
21782
  exports.DEFAULT_POSITION = DEFAULT_POSITION;
21662
21783
  exports.FRACTION_DIGITS = FRACTION_DIGITS;
21663
21784
  exports.LSD_CONTRACT_ID = LSD_CONTRACT_ID;
21785
+ exports.LSD_INTENTS_QUOTE_AUTHORIZATION = LSD_INTENTS_QUOTE_AUTHORIZATION;
21664
21786
  exports.LSD_USDT_DECIMALS = LSD_USDT_DECIMALS;
21665
21787
  exports.MAX_RATIO = MAX_RATIO;
21666
21788
  exports.NDeposit = NDeposit;
@@ -21685,6 +21807,8 @@ exports.decimalMax = decimalMax;
21685
21807
  exports.decimalMin = decimalMin;
21686
21808
  exports.expandToken = expandToken;
21687
21809
  exports.expandTokenDecimal = expandTokenDecimal;
21810
+ exports.fetchIntentsCreateOrder = fetchIntentsCreateOrder;
21811
+ exports.fetchIntentsOrders = fetchIntentsOrders;
21688
21812
  exports.fetchIntentsQuotation = fetchIntentsQuotation;
21689
21813
  exports.fetchIntentsTokens = fetchIntentsTokens;
21690
21814
  exports.fetchIntentsTransactionStatus = fetchIntentsTransactionStatus;
@@ -21713,6 +21837,7 @@ exports.getCreateMcaFeePaged = getCreateMcaFeePaged;
21713
21837
  exports.getFarmDetailsOfAsset = getFarmDetailsOfAsset;
21714
21838
  exports.getListWalletsByMca = getListWalletsByMca;
21715
21839
  exports.getLsdBalances = getLsdBalances;
21840
+ exports.getLsdIntentsOrderHistory = getLsdIntentsOrderHistory;
21716
21841
  exports.getLsdMetadata = getLsdMetadata;
21717
21842
  exports.getLsdTotalSupply = getLsdTotalSupply;
21718
21843
  exports.getMcaByWallet = getMcaByWallet;