@scallop-io/sui-scallop-sdk 1.3.4-alpha.7 → 1.3.4

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.
Files changed (39) hide show
  1. package/dist/constants/common.d.ts +3 -3
  2. package/dist/constants/enum.d.ts +1 -1
  3. package/dist/constants/index.d.ts +1 -0
  4. package/dist/constants/poolAddress.d.ts +1 -1
  5. package/dist/index.js +434 -335
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +434 -335
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/models/scallopQuery.d.ts +11 -3
  10. package/dist/models/scallopUtils.d.ts +1 -1
  11. package/dist/queries/borrowLimitQuery.d.ts +9 -0
  12. package/dist/queries/coreQuery.d.ts +2 -0
  13. package/dist/queries/index.d.ts +1 -0
  14. package/dist/queries/portfolioQuery.d.ts +2 -0
  15. package/dist/queries/sCoinQuery.d.ts +1 -1
  16. package/dist/queries/supplyLimitQuery.d.ts +2 -2
  17. package/dist/types/query/core.d.ts +2 -0
  18. package/dist/types/utils.d.ts +1 -1
  19. package/package.json +1 -1
  20. package/src/constants/coinGecko.ts +4 -2
  21. package/src/constants/common.ts +6 -1
  22. package/src/constants/enum.ts +20 -15
  23. package/src/constants/index.ts +1 -0
  24. package/src/constants/poolAddress.ts +7 -1
  25. package/src/constants/pyth.ts +2 -0
  26. package/src/constants/testAddress.ts +76 -35
  27. package/src/models/scallopBuilder.ts +2 -3
  28. package/src/models/scallopQuery.ts +26 -18
  29. package/src/models/scallopUtils.ts +5 -6
  30. package/src/queries/borrowLimitQuery.ts +52 -0
  31. package/src/queries/coreQuery.ts +238 -229
  32. package/src/queries/index.ts +1 -0
  33. package/src/queries/isolatedAssetQuery.ts +4 -5
  34. package/src/queries/priceQuery.ts +6 -4
  35. package/src/queries/referralQuery.ts +0 -1
  36. package/src/queries/spoolQuery.ts +1 -1
  37. package/src/queries/supplyLimitQuery.ts +22 -18
  38. package/src/types/query/core.ts +2 -0
  39. package/src/types/utils.ts +1 -1
@@ -18,8 +18,8 @@ const isolatedAssetZod = zod.object({
18
18
  }),
19
19
  });
20
20
 
21
- const ISOLATED_ASSET_KEY =
22
- '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey';
21
+ const isolatedAssetKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::IsolatedAssetKey`; // prod
22
+ // const isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
23
23
 
24
24
  /**
25
25
  * Return list of isolated assets coin types
@@ -42,7 +42,7 @@ export const getIsolatedAssets = async (
42
42
  ): dynamicField is DynamicFieldInfo & {
43
43
  name: DynamicFieldName & { value: { type: { name: string } } };
44
44
  } => {
45
- return dynamicField.name.type === ISOLATED_ASSET_KEY;
45
+ return dynamicField.name.type === isolatedAssetKeyType;
46
46
  };
47
47
 
48
48
  do {
@@ -83,7 +83,6 @@ export const isIsolatedAsset = async (
83
83
  ): Promise<boolean> => {
84
84
  try {
85
85
  const marketObject = utils.address.get('core.market');
86
-
87
86
  // check if the coin type is in the list
88
87
  const cachedData = utils.address.cache.queryClient.getQueryData<string[]>([
89
88
  'getDynamicFields',
@@ -100,7 +99,7 @@ export const isIsolatedAsset = async (
100
99
  const object = await utils.cache.queryGetDynamicFieldObject({
101
100
  parentId: marketObject,
102
101
  name: {
103
- type: ISOLATED_ASSET_KEY,
102
+ type: isolatedAssetKeyType,
104
103
  value: coinType,
105
104
  },
106
105
  });
@@ -77,10 +77,12 @@ export const getPythPrices = async (
77
77
  const pythPriceFeed = address.get(
78
78
  `core.coins.${assetCoinName}.oracle.pyth.feedObject`
79
79
  );
80
- if (!prev[pythPriceFeed]) {
81
- prev[pythPriceFeed] = [assetCoinName];
82
- } else {
83
- prev[pythPriceFeed].push(assetCoinName);
80
+ if (pythPriceFeed) {
81
+ if (!prev[pythPriceFeed]) {
82
+ prev[pythPriceFeed] = [assetCoinName];
83
+ } else {
84
+ prev[pythPriceFeed].push(assetCoinName);
85
+ }
84
86
  }
85
87
  return prev;
86
88
  },
@@ -10,7 +10,6 @@ export const queryVeScaKeyIdFromReferralBindings = async (
10
10
  refereeAddress: string
11
11
  ): Promise<string | null> => {
12
12
  const referralBindingTableId = address.get('referral.bindingTableId');
13
-
14
13
  const referralBindResponse = await address.cache.queryGetDynamicFieldObject({
15
14
  parentId: referralBindingTableId,
16
15
  name: {
@@ -114,7 +114,7 @@ export const getSpool = async (
114
114
  const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
115
115
  marketPool = marketPool || (await query.getMarketPool(coinName, indexer));
116
116
  if (!marketPool) {
117
- throw new Error(`Fail to fetch marketPool for ${coinName}`);
117
+ throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
118
118
  }
119
119
 
120
120
  const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
@@ -1,5 +1,5 @@
1
- import { ScallopUtils } from '../models';
2
- import { SupportPoolCoins } from '../types';
1
+ import { ScallopUtils } from 'src/models';
2
+ import { SupportPoolCoins } from 'src/types';
3
3
  import { z as zod } from 'zod';
4
4
 
5
5
  const supplyLimitZod = zod.object({
@@ -17,9 +17,8 @@ const supplyLimitZod = zod.object({
17
17
  }),
18
18
  });
19
19
 
20
- const SUPPLY_LIMIT_KEY =
21
- '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey';
22
-
20
+ const supplyLimitKeyType = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey`; // prod
21
+ // const supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
23
22
  /**
24
23
  * Return supply limit of a pool (including the decimals)
25
24
  * @param utils
@@ -30,19 +29,24 @@ export const getSupplyLimit = async (
30
29
  utils: ScallopUtils,
31
30
  poolName: SupportPoolCoins
32
31
  ) => {
33
- const poolCoinType = utils.parseCoinType(poolName).slice(2);
34
- const marketObject = utils.address.get('core.market');
35
- if (!marketObject) return null;
32
+ try {
33
+ const poolCoinType = utils.parseCoinType(poolName).slice(2);
34
+ const marketObject = utils.address.get('core.market');
35
+ if (!marketObject) return null;
36
36
 
37
- const object = await utils.cache.queryGetDynamicFieldObject({
38
- parentId: marketObject,
39
- name: {
40
- type: SUPPLY_LIMIT_KEY,
41
- value: poolCoinType,
42
- },
43
- });
37
+ const object = await utils.cache.queryGetDynamicFieldObject({
38
+ parentId: marketObject,
39
+ name: {
40
+ type: supplyLimitKeyType,
41
+ value: poolCoinType,
42
+ },
43
+ });
44
44
 
45
- const parsedData = supplyLimitZod.safeParse(object?.data?.content);
46
- if (!parsedData.success) return null;
47
- return parsedData.data.fields.value;
45
+ const parsedData = supplyLimitZod.safeParse(object?.data?.content);
46
+ if (!parsedData.success) return null;
47
+ return parsedData.data.fields.value;
48
+ } catch (e: any) {
49
+ console.error(`Error in getSupplyLimit for ${poolName}: ${e.message}`);
50
+ return '0';
51
+ }
48
52
  };
@@ -130,6 +130,7 @@ export type MarketPool = {
130
130
  coinDecimal: number;
131
131
  coinPrice: number;
132
132
  maxSupplyCoin: number;
133
+ maxBorrowCoin: number;
133
134
  isIsolated: boolean;
134
135
  } & Required<
135
136
  Pick<
@@ -153,6 +154,7 @@ export type MarketCollateral = {
153
154
  coinWrappedType: CoinWrappedType;
154
155
  coinDecimal: number;
155
156
  coinPrice: number;
157
+ isIsolated: boolean;
156
158
  } & Required<
157
159
  Pick<
158
160
  ParsedMarketCollateralData,
@@ -20,7 +20,7 @@ export type PoolAddressInfo = {
20
20
  decimal: number;
21
21
  pythFeedId: string;
22
22
  lendingPoolAddress: string;
23
- collateralPoolAddress: string;
23
+ collateralPoolAddress?: string;
24
24
  sCoinAddress: string | undefined;
25
25
  marketCoinAddress: string;
26
26
  coinAddress: string;