@scallop-io/sui-scallop-sdk 1.4.4 → 1.4.6

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.
@@ -37,7 +37,6 @@ export declare class ScallopCache {
37
37
  * - `all`: All queries that match the refetch predicate will be refetched in the background.
38
38
  * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
39
39
  */
40
- invalidateAllCache(): Promise<Promise<void>[]>;
41
40
  private retryFn;
42
41
  /**
43
42
  * @description Provides cache for inspectTxn of the SuiKit.
@@ -101,6 +101,7 @@ export declare class ScallopQuery {
101
101
  hasui?: import("../types").MarketCollateral | undefined;
102
102
  vsui?: import("../types").MarketCollateral | undefined;
103
103
  sca?: import("../types").MarketCollateral | undefined;
104
+ fdusd?: import("../types").MarketCollateral | undefined;
104
105
  }>;
105
106
  /**
106
107
  * Get market collateral
@@ -313,6 +314,7 @@ export declare class ScallopQuery {
313
314
  sca?: import("../types").BorrowIncentivePool | undefined;
314
315
  fud?: import("../types").BorrowIncentivePool | undefined;
315
316
  deep?: import("../types").BorrowIncentivePool | undefined;
317
+ fdusd?: import("../types").BorrowIncentivePool | undefined;
316
318
  }>;
317
319
  /**
318
320
  * Get borrow incentive accounts data.
@@ -338,6 +340,7 @@ export declare class ScallopQuery {
338
340
  sca?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
339
341
  fud?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
340
342
  deep?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
343
+ fdusd?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
341
344
  }>;
342
345
  /**
343
346
  * Get user lending and spool infomation for specific pools.
@@ -366,6 +369,7 @@ export declare class ScallopQuery {
366
369
  sca?: import("../types").Lending | undefined;
367
370
  fud?: import("../types").Lending | undefined;
368
371
  deep?: import("../types").Lending | undefined;
372
+ fdusd?: import("../types").Lending | undefined;
369
373
  }>;
370
374
  /**
371
375
  * Get user lending and spool information for specific pool.
@@ -476,7 +480,7 @@ export declare class ScallopQuery {
476
480
  * @param ownerAddress - The owner address.
477
481
  * @return All market sCoin amounts.
478
482
  */
479
- getSCoinAmounts(sCoinNames?: SupportSCoin[], ownerAddress?: string): Promise<import("../types").OptionalKeys<Record<"susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep", number>>>;
483
+ getSCoinAmounts(sCoinNames?: SupportSCoin[], ownerAddress?: string): Promise<import("../types").OptionalKeys<Record<"susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep" | "sfdusd", number>>>;
480
484
  /**
481
485
  * Get sCoin amount.
482
486
  *
@@ -491,7 +495,7 @@ export declare class ScallopQuery {
491
495
  * @returns
492
496
  */
493
497
  getSCoinSwapRate(fromSCoin: SupportSCoin, toSCoin: SupportSCoin): Promise<number>;
494
- getFlashLoanFees(assetCoinNames?: SupportAssetCoins[]): Promise<Record<"usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep", number>>;
498
+ getFlashLoanFees(assetCoinNames?: SupportAssetCoins[]): Promise<Record<"usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd", number>>;
495
499
  /**
496
500
  * Get supply limit of lending pool
497
501
  */
@@ -537,6 +541,7 @@ export declare class ScallopQuery {
537
541
  ssca?: number | undefined;
538
542
  sfud?: number | undefined;
539
543
  sdeep?: number | undefined;
544
+ sfdusd?: number | undefined;
540
545
  usdc?: number | undefined;
541
546
  sbeth?: number | undefined;
542
547
  weth?: number | undefined;
@@ -553,13 +558,14 @@ export declare class ScallopQuery {
553
558
  sca?: number | undefined;
554
559
  fud?: number | undefined;
555
560
  deep?: number | undefined;
561
+ fdusd?: number | undefined;
556
562
  swapt?: number | undefined;
557
563
  }>;
558
564
  /**
559
565
  * Query all address (lending pool, collateral pool, borrow dynamics, interest models) of all pool
560
566
  * @returns
561
567
  */
562
- getPoolAddresses(): Promise<import("../types").OptionalKeys<Record<"usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep", {
568
+ getPoolAddresses(): Promise<import("../types").OptionalKeys<Record<"usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd", {
563
569
  lendingPoolAddress?: string;
564
570
  collateralPoolAddress?: string;
565
571
  borrowDynamic?: string;
@@ -65,7 +65,7 @@ export declare class ScallopUtils {
65
65
  * if no `scallop_...` is encountered, return coinName
66
66
  * @return sCoin name
67
67
  */
68
- parseSCoinTypeNameToMarketCoinName(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" | "sfdusd";
69
69
  /**
70
70
  * Convert sCoin name into sCoin type
71
71
  * @param sCoinName
@@ -77,7 +77,7 @@ export declare class ScallopUtils {
77
77
  * @param sCoinType
78
78
  * @returns sCoin name
79
79
  */
80
- parseSCoinNameFromType(sCoinType: string): "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep";
80
+ parseSCoinNameFromType(sCoinType: string): "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep" | "sfdusd";
81
81
  /**
82
82
  * Convert sCoin name into its underlying coin type
83
83
  * @param sCoinName
@@ -32,6 +32,7 @@ export declare const getBorrowIncentivePools: (query: ScallopQuery, borrowIncent
32
32
  sca?: BorrowIncentivePool | undefined;
33
33
  fud?: BorrowIncentivePool | undefined;
34
34
  deep?: BorrowIncentivePool | undefined;
35
+ fdusd?: BorrowIncentivePool | undefined;
35
36
  }>;
36
37
  /**
37
38
  * Query borrow incentive accounts data.
@@ -59,6 +60,7 @@ export declare const queryBorrowIncentiveAccounts: ({ utils, }: {
59
60
  sca?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
60
61
  fud?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
61
62
  deep?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
63
+ fdusd?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
62
64
  }>;
63
65
  /**
64
66
  * Check veSca bind status
@@ -80,6 +80,7 @@ export declare const getMarketCollaterals: (query: ScallopQuery, collateralCoinN
80
80
  hasui?: MarketCollateral | undefined;
81
81
  vsui?: MarketCollateral | undefined;
82
82
  sca?: MarketCollateral | undefined;
83
+ fdusd?: MarketCollateral | undefined;
83
84
  }>;
84
85
  /**
85
86
  * Get market collateral data.
@@ -1,6 +1,6 @@
1
1
  import { ScallopQuery } from 'src/models';
2
2
  import { OptionalKeys } from 'src/types';
3
- export declare const getAllAddresses: (query: ScallopQuery) => Promise<OptionalKeys<Record<"usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep", {
3
+ export declare const getAllAddresses: (query: ScallopQuery) => Promise<OptionalKeys<Record<"usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd", {
4
4
  lendingPoolAddress?: string;
5
5
  collateralPoolAddress?: string;
6
6
  borrowDynamic?: string;
@@ -27,6 +27,7 @@ export declare const getLendings: (query: ScallopQuery, poolCoinNames?: SupportP
27
27
  sca?: Lending | undefined;
28
28
  fud?: Lending | undefined;
29
29
  deep?: Lending | undefined;
30
+ fdusd?: Lending | undefined;
30
31
  }>;
31
32
  /**
32
33
  * Get user lending infomation for specific pool.
@@ -30,6 +30,7 @@ export declare const getAllCoinPrices: (query: ScallopQuery, marketPools?: Marke
30
30
  ssca?: number | undefined;
31
31
  sfud?: number | undefined;
32
32
  sdeep?: number | undefined;
33
+ sfdusd?: number | undefined;
33
34
  usdc?: number | undefined;
34
35
  sbeth?: number | undefined;
35
36
  weth?: number | undefined;
@@ -46,5 +47,6 @@ export declare const getAllCoinPrices: (query: ScallopQuery, marketPools?: Marke
46
47
  sca?: number | undefined;
47
48
  fud?: number | undefined;
48
49
  deep?: number | undefined;
50
+ fdusd?: number | undefined;
49
51
  swapt?: number | undefined;
50
52
  }>;
@@ -19,7 +19,7 @@ export declare const getSCoinTotalSupply: ({ utils, }: {
19
19
  */
20
20
  export declare const getSCoinAmounts: ({ utils, }: {
21
21
  utils: ScallopUtils;
22
- }, sCoinNames?: SupportSCoin[], ownerAddress?: string) => Promise<OptionalKeys<Record<"susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep", number>>>;
22
+ }, sCoinNames?: SupportSCoin[], ownerAddress?: string) => Promise<OptionalKeys<Record<"susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep" | "sfdusd", number>>>;
23
23
  /**
24
24
  * Query owned sCoin amount.
25
25
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -15,6 +15,7 @@ export const COIN_GECKGO_IDS: Record<SupportPoolCoins, string> = {
15
15
  hasui: 'sui',
16
16
  vsui: 'sui',
17
17
  sca: 'scallop-2',
18
+ fdusd: 'first-digital-usd',
18
19
  deep: 'deepbook',
19
20
  fud: 'fud-the-pug',
20
21
  };
@@ -46,6 +46,7 @@ export const SUPPORT_POOLS = [
46
46
  'sca',
47
47
  'fud',
48
48
  'deep',
49
+ 'fdusd',
49
50
  ] as const;
50
51
 
51
52
  export const SUPPORT_COLLATERALS = [
@@ -63,6 +64,7 @@ export const SUPPORT_COLLATERALS = [
63
64
  'hasui',
64
65
  'vsui',
65
66
  'sca',
67
+ 'fdusd',
66
68
  ] as const;
67
69
 
68
70
  export const SUPPORT_SPOOLS = [
@@ -93,6 +95,7 @@ export const SUPPORT_SCOIN = [
93
95
  'swbtc',
94
96
  'sdeep',
95
97
  'sfud',
98
+ 'sfdusd',
96
99
  ] as const;
97
100
 
98
101
  export const SUPPORT_SUI_BRIDGE = ['sbeth'] as const;
@@ -16,6 +16,7 @@ export const coinDecimals: types.SupportCoinDecimals = {
16
16
  hasui: 9,
17
17
  vsui: 9,
18
18
  sca: 9,
19
+ fdusd: 6,
19
20
  deep: 6,
20
21
  fud: 5,
21
22
  susdc: 6,
@@ -32,6 +33,7 @@ export const coinDecimals: types.SupportCoinDecimals = {
32
33
  shasui: 9,
33
34
  svsui: 9,
34
35
  ssca: 9,
36
+ sfdusd: 6,
35
37
  sdeep: 6,
36
38
  sfud: 5,
37
39
  };
@@ -51,6 +53,7 @@ export const assetCoins: types.AssetCoins = {
51
53
  hasui: 'hasui',
52
54
  vsui: 'vsui',
53
55
  sca: 'sca',
56
+ fdusd: 'fdusd',
54
57
  deep: 'deep',
55
58
  fud: 'fud',
56
59
  };
@@ -70,6 +73,7 @@ export const marketCoins: types.MarketCoins = {
70
73
  shasui: 'shasui',
71
74
  svsui: 'svsui',
72
75
  ssca: 'ssca',
76
+ sfdusd: 'sfdusd',
73
77
  sdeep: 'sdeep',
74
78
  sfud: 'sfud',
75
79
  };
@@ -88,6 +92,7 @@ export const sCoins: types.SCoins = {
88
92
  ssca: 'ssca',
89
93
  swsol: 'swsol',
90
94
  swbtc: 'swbtc',
95
+ sfdusd: 'sfdusd',
91
96
  sfud: 'sfud',
92
97
  sdeep: 'sdeep',
93
98
  };
@@ -137,6 +142,7 @@ export const coinIds: types.AssetCoinIds = {
137
142
  sca: IS_VE_SCA_TEST
138
143
  ? '0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524'
139
144
  : '0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6',
145
+ fdusd: '0xf16e6b723f242ec745dfd7634ad072c42d5c1d9ac9d62a39c381303eaa57693a',
140
146
  // isolated assets
141
147
  deep: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270',
142
148
  fud: '0x76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1',
@@ -181,6 +187,8 @@ export const sCoinIds: types.SCoinIds = {
181
187
  '0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL',
182
188
  swbtc:
183
189
  '0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC',
190
+ sfdusd:
191
+ '0x6711551c1e7652a270d9fbf0eee25d99594c157cde3cb5fbb49035eb59b1b001::scallop_fdusd::SCALLOP_FDUSD',
184
192
  sdeep:
185
193
  '0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP',
186
194
  sfud: '0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD',
@@ -425,4 +425,29 @@ export const POOL_ADDRESSES: OptionalKeys<
425
425
  coinDecimalId:
426
426
  '0x6e60b051a08fa836f5a7acd7c464c8d9825bc29c44657fe170fe9b8e1e4770c0',
427
427
  },
428
+ fdusd: {
429
+ lendingPoolAddress:
430
+ '0x4f46051a01f05c3ad9aecf29a771aad5c884e1a1888e08d7709085e3a095bc9c',
431
+ collateralPoolAddress:
432
+ '0x4f6647a9afcfdb62bb9b27e4d1cb7bd7130aca1b4f13fa7164453c869c1681ae',
433
+ borrowDynamic:
434
+ '0x4ddcf19b6290a8b048ecb314b14ef7f52c1c5b9ddc9259a2a242cd91d681a085',
435
+ interestModel:
436
+ '0xb57a33706b29d2d253c74c1c0869e6e20da99036338d2b0b7235ab41621ee9dd',
437
+ riskModel:
438
+ '0xd65fb21758dc1e6184940a1a27efb13228d7cf5e19f6dcca06cc2d996af4a6b9',
439
+ borrowFeeKey:
440
+ '0xafe673a27747b063fa918d2dfe47794e44af553737ac562c2a63186539a07f45',
441
+ supplyLimitKey:
442
+ '0x730e0785ba056a7a95f4a6959371a598d7fe782e81c40785c79982ced4cf4e35',
443
+ borrowLimitKey:
444
+ '0x1630c6954918a06fe56312afb8958366c5ed7af653dae0e32c09d088da38577e',
445
+ isolatedAssetKey: undefined,
446
+ spool: undefined,
447
+ spoolReward: undefined,
448
+ sCoinTreasury:
449
+ '0xdad9bc6293e694f67a5274ea51b596e0bdabfafc585ae6d7e82888e65f1a03e0',
450
+ coinDecimalId:
451
+ '0xdebee5265a67c186ed87fe93303d33dfe1de53e3b4fd7d9329c2852860acd3e7',
452
+ },
428
453
  };
@@ -22,6 +22,7 @@ export const PYTH_FEED_IDS: Record<SupportPoolCoins, string> = {
22
22
  hasui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
23
23
  vsui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
24
24
  sca: '7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc',
25
+ fdusd: '0xccdc1a08923e2e4f4b1e6ea89de6acbc5fe1948e9706f5604b8cb50bc1ed3979',
25
26
  deep: '29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff',
26
27
  fud: '6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75',
27
28
  };
@@ -49,7 +49,7 @@ export const queryKeys = {
49
49
  {
50
50
  walletAddress,
51
51
  options,
52
- objectIds: JSON.stringify(objectIds ?? []),
52
+ objectIds: JSON.stringify(objectIds ?? undefined),
53
53
  },
54
54
  ],
55
55
  getOwnedObjects: (input?: Partial<GetOwnedObjectsParams>) => [
@@ -236,6 +236,21 @@ export const TEST_ADDRESSES: AddressesInterface = {
236
236
  },
237
237
  },
238
238
  },
239
+ fdusd: {
240
+ id: '0xf16e6b723f242ec745dfd7634ad072c42d5c1d9ac9d62a39c381303eaa57693a',
241
+ metaData:
242
+ '0xdebee5265a67c186ed87fe93303d33dfe1de53e3b4fd7d9329c2852860acd3e7',
243
+ treasury: '',
244
+ oracle: {
245
+ supra: '',
246
+ switchboard: '',
247
+ pyth: {
248
+ feed: '0xccdc1a08923e2e4f4b1e6ea89de6acbc5fe1948e9706f5604b8cb50bc1ed3979',
249
+ feedObject:
250
+ '0x5f6583b2b0fe1ecf94aaffeaab8a838794693960cea48c0da282d5f4a24be027',
251
+ },
252
+ },
253
+ },
239
254
  deep: {
240
255
  id: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270',
241
256
  metaData:
@@ -543,6 +558,12 @@ export const TEST_ADDRESSES: AddressesInterface = {
543
558
  treasury:
544
559
  '0xfd0f02def6358a1f266acfa1493d4707ee8387460d434fb667d63d755ff907ed',
545
560
  },
561
+ sfdusd: {
562
+ coinType:
563
+ '0x6711551c1e7652a270d9fbf0eee25d99594c157cde3cb5fbb49035eb59b1b001::scallop_fdusd::SCALLOP_FDUSD',
564
+ treasury:
565
+ '0xdad9bc6293e694f67a5274ea51b596e0bdabfafc585ae6d7e82888e65f1a03e0',
566
+ },
546
567
  sdeep: {
547
568
  coinType:
548
569
  '0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP',
@@ -98,14 +98,14 @@ export class ScallopCache {
98
98
  * - `all`: All queries that match the refetch predicate will be refetched in the background.
99
99
  * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
100
100
  */
101
- public async invalidateAllCache() {
102
- return Object.values(queryKeys.rpc).map((t) =>
103
- this.queryClient.invalidateQueries({
104
- queryKey: t(),
105
- type: 'all',
106
- })
107
- );
108
- }
101
+ // public async invalidateAllCache() {
102
+ // return Object.values(queryKeys.rpc).map((t) =>
103
+ // this.queryClient.invalidateQueries({
104
+ // queryKey: t(),
105
+ // type: 'all',
106
+ // })
107
+ // );
108
+ // }
109
109
 
110
110
  private retryFn(errCount: number, e: any) {
111
111
  if (errCount === 5) return false;
@@ -292,33 +292,65 @@ const queryRequiredMarketObjects = async (
292
292
  // Map the results back to poolCoinNames
293
293
  const mapObjects = (
294
294
  tasks: { poolCoinName: string; [key: string]: string | undefined }[],
295
- fetchedObjects: SuiObjectData[]
295
+ fetchedObjects: SuiObjectData[],
296
+ keyValue: string
296
297
  ) => {
297
298
  const resultMap: Record<string, SuiObjectData> = {};
298
- let fetchedIndex = 0;
299
+ const fetchedObjectMap = fetchedObjects.reduce(
300
+ (acc, obj) => {
301
+ acc[obj.objectId] = obj;
302
+ return acc;
303
+ },
304
+ {} as Record<string, SuiObjectData>
305
+ );
299
306
 
300
307
  for (const task of tasks) {
301
- const key = task[Object.keys(task)[1]]; // current object key being queried
302
- if (key) {
303
- resultMap[task.poolCoinName] = fetchedObjects[fetchedIndex];
304
- fetchedIndex++;
308
+ if (task[keyValue]) {
309
+ resultMap[task.poolCoinName] = fetchedObjectMap[task[keyValue]];
305
310
  }
306
311
  }
307
312
  return resultMap;
308
313
  };
309
314
 
310
- const balanceSheetMap = mapObjects(tasks, balanceSheetObjects);
311
- const collateralStatMap = mapObjects(tasks, collateralStatObjects);
312
- const borrowDynamicMap = mapObjects(tasks, borrowDynamicObjects);
313
- const interestModelMap = mapObjects(tasks, interestModelObjects);
314
- const riskModelMap = mapObjects(tasks, riskModelObjects);
315
- const borrowFeeMap = mapObjects(tasks, borrowFeeObjects);
316
- const supplyLimitMap = mapObjects(tasks, supplyLimitObjects);
317
- const borrowLimitMap = mapObjects(tasks, borrowLimitObjects);
318
- const isolatedAssetMap = mapObjects(tasks, isolatedAssetObjects);
319
-
315
+ const balanceSheetMap = mapObjects(
316
+ tasks,
317
+ balanceSheetObjects,
318
+ 'balanceSheet'
319
+ );
320
+ const collateralStatMap = mapObjects(
321
+ tasks,
322
+ collateralStatObjects,
323
+ 'collateralStat'
324
+ );
325
+ const borrowDynamicMap = mapObjects(
326
+ tasks,
327
+ borrowDynamicObjects,
328
+ 'borrowDynamic'
329
+ );
330
+ const interestModelMap = mapObjects(
331
+ tasks,
332
+ interestModelObjects,
333
+ 'interestModel'
334
+ );
335
+ const riskModelMap = mapObjects(tasks, riskModelObjects, 'riskModel');
336
+ const borrowFeeMap = mapObjects(tasks, borrowFeeObjects, 'borrowFeeKey');
337
+ const supplyLimitMap = mapObjects(
338
+ tasks,
339
+ supplyLimitObjects,
340
+ 'supplyLimitKey'
341
+ );
342
+ const borrowLimitMap = mapObjects(
343
+ tasks,
344
+ borrowLimitObjects,
345
+ 'borrowLimitKey'
346
+ );
347
+ const isolatedAssetMap = mapObjects(
348
+ tasks,
349
+ isolatedAssetObjects,
350
+ 'isolatedAssetKey'
351
+ );
320
352
  // Construct the final requiredObjects result
321
- return poolCoinNames.reduce(
353
+ const result = poolCoinNames.reduce(
322
354
  (acc, name) => {
323
355
  acc[name] = {
324
356
  balanceSheet: balanceSheetMap[name],
@@ -348,6 +380,8 @@ const queryRequiredMarketObjects = async (
348
380
  }
349
381
  >
350
382
  );
383
+
384
+ return result;
351
385
  };
352
386
 
353
387
  /**
@@ -58,24 +58,33 @@ const queryRequiredSpoolObjects = async (
58
58
  // Map the results back to poolCoinNames
59
59
  const mapObjects = (
60
60
  tasks: { poolCoinName: string; [key: string]: string | undefined }[],
61
- fetchedObjects: SuiObjectData[]
61
+ fetchedObjects: SuiObjectData[],
62
+ keyValue: string
62
63
  ) => {
63
64
  const resultMap: Record<string, SuiObjectData> = {};
64
- let fetchedIndex = 0;
65
+ const fetchedObjectMap = fetchedObjects.reduce(
66
+ (acc, obj) => {
67
+ acc[obj.objectId] = obj;
68
+ return acc;
69
+ },
70
+ {} as Record<string, SuiObjectData>
71
+ );
65
72
 
66
73
  for (const task of tasks) {
67
- const key = task[Object.keys(task)[1]]; // current object key being queried
68
- if (key) {
69
- resultMap[task.poolCoinName] = fetchedObjects[fetchedIndex];
70
- fetchedIndex++;
74
+ if (task[keyValue]) {
75
+ resultMap[task.poolCoinName] = fetchedObjectMap[task[keyValue]];
71
76
  }
72
77
  }
73
78
  return resultMap;
74
79
  };
75
80
 
76
- const spoolMap = mapObjects(tasks, spoolObjects);
77
- const spoolRewardMap = mapObjects(tasks, spoolRewardObjects);
78
- const sCoinTreasuryMap = mapObjects(tasks, sCoinTreasuryObjects);
81
+ const spoolMap = mapObjects(tasks, spoolObjects, 'spool');
82
+ const spoolRewardMap = mapObjects(tasks, spoolRewardObjects, 'spoolReward');
83
+ const sCoinTreasuryMap = mapObjects(
84
+ tasks,
85
+ sCoinTreasuryObjects,
86
+ 'sCoinTreasury'
87
+ );
79
88
 
80
89
  // Construct the final requiredObjects result
81
90
  return stakePoolCoinNames.reduce(
@@ -167,10 +167,10 @@ export const calculateMarketPoolData = (
167
167
  conversionRate: conversionRate.toNumber(),
168
168
  isIsolated: parsedMarketPoolData.isIsolated,
169
169
  maxSupplyCoin: BigNumber(parsedMarketPoolData.supplyLimit)
170
- .shiftedBy(coinDecimal)
170
+ .shiftedBy(-coinDecimal)
171
171
  .toNumber(),
172
172
  maxBorrowCoin: BigNumber(parsedMarketPoolData.borrowLimit)
173
- .shiftedBy(coinDecimal)
173
+ .shiftedBy(-coinDecimal)
174
174
  .toNumber(),
175
175
  };
176
176
  };