@scallop-io/sui-scallop-sdk 1.4.13 → 1.4.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/dist/index.js CHANGED
@@ -1441,7 +1441,7 @@ var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointDa
1441
1441
  createdAt: Number(originBorrowIncentivePoolPointData.created_at)
1442
1442
  };
1443
1443
  };
1444
- var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
1444
+ var parseOriginBorrowIncentivePoolData = (utils, originBorrowIncentivePoolData) => {
1445
1445
  return {
1446
1446
  poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
1447
1447
  minStakes: Number(originBorrowIncentivePoolData.min_stakes),
@@ -1450,12 +1450,9 @@ var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
1450
1450
  poolPoints: originBorrowIncentivePoolData.points.reduce(
1451
1451
  (acc, point) => {
1452
1452
  const parsed = parseOriginBorrowIncentivesPoolPointData(point);
1453
- let name = (0, import_utils.parseStructTag)(
1454
- parsed.pointType
1455
- ).name.toLowerCase();
1456
- if (sCoinRawNameToName[name]) {
1457
- name = sCoinRawNameToName[name];
1458
- }
1453
+ const name = utils.parseSCoinTypeNameToMarketCoinName(
1454
+ (0, import_utils.parseStructTag)(parsed.pointType).name.toLowerCase()
1455
+ );
1459
1456
  acc[name] = parsed;
1460
1457
  return acc;
1461
1458
  },
@@ -2612,7 +2609,10 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2612
2609
  );
2613
2610
  for (const pool of borrowIncentivePoolsQueryData?.incentive_pools ?? []) {
2614
2611
  const borrowIncentivePoolPoints = {};
2615
- const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
2612
+ const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
2613
+ query.utils,
2614
+ pool
2615
+ );
2616
2616
  const poolCoinType = (0, import_utils3.normalizeStructTag)(pool.pool_type.name);
2617
2617
  const poolCoinName = query.utils.parseCoinNameFromType(
2618
2618
  poolCoinType
@@ -2626,12 +2626,9 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2626
2626
  parsedBorrowIncentivePoolData.poolPoints
2627
2627
  )) {
2628
2628
  const rewardCoinType = poolPoint.pointType;
2629
- let rewardCoinName = query.utils.parseCoinNameFromType(
2629
+ const rewardCoinName = query.utils.parseCoinNameFromType(
2630
2630
  rewardCoinType
2631
2631
  );
2632
- if (sCoinRawNameToName[rewardCoinName]) {
2633
- rewardCoinName = sCoinRawNameToName[rewardCoinName];
2634
- }
2635
2632
  const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
2636
2633
  const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
2637
2634
  const symbol = query.utils.parseSymbol(rewardCoinName);
@@ -3941,7 +3938,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3941
3938
  const rewards = [];
3942
3939
  Object.entries(borrowIncentiveAccount.pointList).forEach(
3943
3940
  ([key, accountPoint]) => {
3944
- const poolPoint = borrowIncentivePool.points[key];
3941
+ const poolPoint = borrowIncentivePool.points[query.utils.parseSCoinTypeNameToMarketCoinName(key)];
3945
3942
  if (accountPoint && poolPoint) {
3946
3943
  let availableClaimAmount = (0, import_bignumber5.default)(0);
3947
3944
  let availableClaimCoin = (0, import_bignumber5.default)(0);
@@ -4973,13 +4970,14 @@ var ScallopUtils = class {
4973
4970
  }
4974
4971
  }
4975
4972
  /**
4976
- * Convert sCoin name to coin name.
4973
+ * Convert sCoin name to market coin name.
4977
4974
  * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
4978
4975
  * e.g: `scallop_sui -> ssui
4976
+ * if no `scallop_...` is encountered, return coinName
4979
4977
  * @return sCoin name
4980
4978
  */
4981
- parseCoinNameFromSCoinName(coinName) {
4982
- return sCoinRawNameToName[coinName];
4979
+ parseSCoinTypeNameToMarketCoinName(coinName) {
4980
+ return sCoinRawNameToName[coinName] ?? coinName;
4983
4981
  }
4984
4982
  /**
4985
4983
  * Convert sCoin name into sCoin type
@@ -5028,6 +5026,9 @@ var ScallopUtils = class {
5028
5026
  }
5029
5027
  parseCoinNameFromType(coinType) {
5030
5028
  coinType = (0, import_utils10.normalizeStructTag)(coinType);
5029
+ if (sCoinTypeToName[coinType]) {
5030
+ return sCoinTypeToName[coinType];
5031
+ }
5031
5032
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
5032
5033
  const coinTypeMatch = coinType.match(coinTypeRegex);
5033
5034
  const isMarketCoinType = coinType.includes("reserve::MarketCoin");