@scallop-io/sui-scallop-sdk 1.4.3 → 1.4.5

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.
@@ -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
  };