@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.
@@ -59,12 +59,13 @@ export declare class ScallopUtils {
59
59
  */
60
60
  parseSCoinName<T extends SupportSCoin>(coinName: SupportCoins | SupportMarketCoins): T | undefined;
61
61
  /**
62
- * Convert sCoin name to coin name.
62
+ * Convert sCoin name to market coin name.
63
63
  * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
64
64
  * e.g: `scallop_sui -> ssui
65
+ * if no `scallop_...` is encountered, return coinName
65
66
  * @return sCoin name
66
67
  */
67
- parseCoinNameFromSCoinName(coinName: string): "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep";
68
+ parseSCoinTypeNameToMarketCoinName(coinName: string): "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep";
68
69
  /**
69
70
  * Convert sCoin name into sCoin type
70
71
  * @param sCoinName
@@ -110,6 +111,7 @@ export declare class ScallopUtils {
110
111
  parseCoinNameFromType<T extends SupportAssetCoins>(coinType: string): T extends SupportAssetCoins ? T : SupportAssetCoins;
111
112
  parseCoinNameFromType<T extends SupportMarketCoins>(coinType: string): T extends SupportMarketCoins ? T : SupportMarketCoins;
112
113
  parseCoinNameFromType<T extends SupportCoins>(coinType: string): T extends SupportCoins ? T : SupportCoins;
114
+ parseCoinNameFromType<T extends SupportSCoin>(coinType: string): T extends SupportSCoin ? T : SupportSCoin;
113
115
  /**
114
116
  * Convert market coin name to coin name.
115
117
  *
@@ -40,7 +40,7 @@ export declare const parseOriginBorrowIncentivesPoolPointData: (originBorrowInce
40
40
  * @param originBorrowIncentivePoolData - Origin borrow incentive pool data
41
41
  * @return Parsed borrow incentive pool data
42
42
  */
43
- export declare const parseOriginBorrowIncentivePoolData: (originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
43
+ export declare const parseOriginBorrowIncentivePoolData: (utils: ScallopUtils, originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
44
44
  export declare const calculateBorrowIncentivePoolPointData: (parsedBorrowIncentivePoolPointData: ParsedBorrowIncentivePoolPointData, rewardCoinPrice: number, rewardCoinDecimal: number, poolCoinPrice: number, poolCoinDecimal: number) => CalculatedBorrowIncentivePoolPointData;
45
45
  export declare const parseOriginBorrowIncentiveAccountPoolPointData: (originBorrowIncentiveAccountPoolPointData: OriginBorrowIncentiveAccountPoolData) => ParsedBorrowIncentiveAccountPoolData;
46
46
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "1.4.13",
3
+ "version": "1.4.14",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -232,13 +232,14 @@ export class ScallopUtils {
232
232
  }
233
233
 
234
234
  /**
235
- * Convert sCoin name to coin name.
235
+ * Convert sCoin name to market coin name.
236
236
  * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
237
237
  * e.g: `scallop_sui -> ssui
238
+ * if no `scallop_...` is encountered, return coinName
238
239
  * @return sCoin name
239
240
  */
240
- public parseCoinNameFromSCoinName(coinName: string) {
241
- return sCoinRawNameToName[coinName];
241
+ public parseSCoinTypeNameToMarketCoinName(coinName: string) {
242
+ return sCoinRawNameToName[coinName] ?? coinName;
242
243
  }
243
244
 
244
245
  /**
@@ -311,8 +312,14 @@ export class ScallopUtils {
311
312
  public parseCoinNameFromType<T extends SupportCoins>(
312
313
  coinType: string
313
314
  ): T extends SupportCoins ? T : SupportCoins;
315
+ public parseCoinNameFromType<T extends SupportSCoin>(
316
+ coinType: string
317
+ ): T extends SupportSCoin ? T : SupportSCoin;
314
318
  public parseCoinNameFromType(coinType: string) {
315
319
  coinType = normalizeStructTag(coinType);
320
+ if (sCoinTypeToName[coinType]) {
321
+ return sCoinTypeToName[coinType] as SupportSCoin;
322
+ }
316
323
 
317
324
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
318
325
  const coinTypeMatch = coinType.match(coinTypeRegex);
@@ -1,6 +1,5 @@
1
1
  import { normalizeStructTag } from '@mysten/sui/utils';
2
2
  import {
3
- sCoinRawNameToName,
4
3
  SUPPORT_BORROW_INCENTIVE_POOLS,
5
4
  SUPPORT_BORROW_INCENTIVE_REWARDS,
6
5
  } from '../constants';
@@ -100,8 +99,10 @@ export const getBorrowIncentivePools = async (
100
99
  const borrowIncentivePoolPoints: OptionalKeys<
101
100
  Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
102
101
  > = {};
103
- const parsedBorrowIncentivePoolData =
104
- parseOriginBorrowIncentivePoolData(pool);
102
+ const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
103
+ query.utils,
104
+ pool
105
+ );
105
106
 
106
107
  const poolCoinType = normalizeStructTag(pool.pool_type.name);
107
108
  const poolCoinName =
@@ -121,13 +122,10 @@ export const getBorrowIncentivePools = async (
121
122
  parsedBorrowIncentivePoolData.poolPoints
122
123
  )) {
123
124
  const rewardCoinType = poolPoint.pointType;
124
- let rewardCoinName = query.utils.parseCoinNameFromType(
125
+ const rewardCoinName = query.utils.parseCoinNameFromType(
125
126
  rewardCoinType
126
127
  ) as SupportBorrowIncentiveRewardCoins;
127
128
  // handle for scoin name
128
- if (sCoinRawNameToName[rewardCoinName]) {
129
- rewardCoinName = sCoinRawNameToName[rewardCoinName];
130
- }
131
129
  const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
132
130
  const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
133
131
 
@@ -532,7 +532,7 @@ export const getObligationAccount = async (
532
532
  ([key, accountPoint]) => {
533
533
  const poolPoint =
534
534
  borrowIncentivePool.points[
535
- key as SupportBorrowIncentiveRewardCoins
535
+ query.utils.parseSCoinTypeNameToMarketCoinName(key)
536
536
  ];
537
537
 
538
538
  if (accountPoint && poolPoint) {
@@ -577,6 +577,11 @@ export const getObligationAccount = async (
577
577
  .toNumber()
578
578
  : 1;
579
579
 
580
+ // console.log({
581
+ // availableClaimAmount: availableClaimAmount.toString(),
582
+ // coinName: poolPoint.coinName,
583
+ // coinType: poolPoint.coinType,
584
+ // });
580
585
  if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
581
586
  rewards.push({
582
587
  coinName: poolPoint.coinName,
@@ -27,7 +27,6 @@ import type {
27
27
  ParsedBorrowIncentiveAccountPoolData,
28
28
  SupportBorrowIncentiveRewardCoins,
29
29
  } from '../types';
30
- import { sCoinRawNameToName } from 'src/constants';
31
30
 
32
31
  /**
33
32
  * Parse origin market pool data to a more readable format.
@@ -424,6 +423,7 @@ export const parseOriginBorrowIncentivesPoolPointData = (
424
423
  * @return Parsed borrow incentive pool data
425
424
  */
426
425
  export const parseOriginBorrowIncentivePoolData = (
426
+ utils: ScallopUtils,
427
427
  originBorrowIncentivePoolData: OriginBorrowIncentivePoolData
428
428
  ): ParsedBorrowIncentivePoolData => {
429
429
  return {
@@ -434,12 +434,10 @@ export const parseOriginBorrowIncentivePoolData = (
434
434
  poolPoints: originBorrowIncentivePoolData.points.reduce(
435
435
  (acc, point) => {
436
436
  const parsed = parseOriginBorrowIncentivesPoolPointData(point);
437
- let name = parseStructTag(
438
- parsed.pointType
439
- ).name.toLowerCase() as SupportBorrowIncentiveRewardCoins;
440
- if (sCoinRawNameToName[name]) {
441
- name = sCoinRawNameToName[name];
442
- }
437
+ const name = utils.parseSCoinTypeNameToMarketCoinName(
438
+ parseStructTag(parsed.pointType).name.toLowerCase()
439
+ ) as SupportBorrowIncentiveRewardCoins;
440
+
443
441
  acc[name] = parsed;
444
442
  return acc;
445
443
  },