@scallop-io/sui-scallop-sdk 2.0.3 → 2.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -852,7 +852,7 @@ export const getUserPortfolio = async (
852
852
  walletAddress: string,
853
853
  indexer: boolean = false
854
854
  ) => {
855
- const coinPrices = await query.utils.getCoinPrices();
855
+ const coinPrices = await query.getAllCoinPrices({ indexer });
856
856
  const market = await query.getMarketPools(undefined, { indexer, coinPrices });
857
857
 
858
858
  const [lendings, obligationAccounts, borrowIncentivePools, veScas] =
@@ -908,6 +908,20 @@ export const getUserPortfolio = async (
908
908
  obligationAccount.totalAvailableCollateralValue,
909
909
  totalUnhealthyCollateralInUsd:
910
910
  obligationAccount.totalUnhealthyCollateralValue,
911
+ collaterals: Object.values(obligationAccount.collaterals)
912
+ .filter(
913
+ (collateral): collateral is NonNullable<typeof collateral> =>
914
+ !!collateral && collateral.depositedCoin > 0
915
+ )
916
+ .map((collateral) => ({
917
+ coinName: collateral.coinName,
918
+ symbol: collateral.symbol,
919
+ coinDecimals: collateral.coinDecimal,
920
+ coinType: collateral.coinType,
921
+ coinPrice: collateral.coinPrice,
922
+ depositedCoin: collateral.depositedCoin,
923
+ depositedValueInUsd: collateral.depositedValue,
924
+ })),
911
925
  borrowedPools: Object.values(obligationAccount.debts)
912
926
  .filter(
913
927
  (debt): debt is NonNullable<typeof debt> =>
@@ -939,19 +953,22 @@ export const getUserPortfolio = async (
939
953
  };
940
954
  });
941
955
 
956
+ const LENDING_SPOOL_REWARD_COIN_NAME = 'sui' as const;
957
+ const LENDING_SPOOL_REWARD_COIN_SYMBOL = 'SUI' as const;
942
958
  const pendingLendingRewards = Object.values(lendings).reduce(
943
959
  (acc, reward) => {
944
960
  if (reward) {
945
961
  if (reward.availableClaimCoin === 0) return acc;
946
- if (!acc[reward.symbol]) {
947
- acc[reward.symbol] = {
948
- symbol: reward.symbol,
962
+ if (!acc[LENDING_SPOOL_REWARD_COIN_NAME]) {
963
+ acc[LENDING_SPOOL_REWARD_COIN_NAME] = {
964
+ symbol: LENDING_SPOOL_REWARD_COIN_SYMBOL,
949
965
  coinType: normalizeStructTag(SUI_TYPE_ARG), // @TODO: for now lending reward is all in SUI
950
- coinPrice: reward.coinPrice,
966
+ coinPrice: coinPrices[LENDING_SPOOL_REWARD_COIN_NAME] ?? 0,
951
967
  pendingRewardInCoin: reward.availableClaimCoin,
952
968
  };
953
969
  } else {
954
- acc[reward.symbol].pendingRewardInCoin += reward.availableClaimCoin;
970
+ acc[LENDING_SPOOL_REWARD_COIN_NAME].pendingRewardInCoin +=
971
+ reward.availableClaimCoin;
955
972
  }
956
973
  }
957
974
  return acc;
@@ -1040,10 +1057,10 @@ export const getUserPortfolio = async (
1040
1057
  borrowings: parsedObligationAccounts,
1041
1058
  pendingRewards: {
1042
1059
  lendings: Object.entries(pendingLendingRewards).reduce(
1043
- (acc, [key, value]) => {
1060
+ (acc, [_, value]) => {
1044
1061
  acc.push({
1045
1062
  ...value,
1046
- coinName: key,
1063
+ coinName: 'sui',
1047
1064
  pendingRewardInUsd: value.coinPrice * value.pendingRewardInCoin,
1048
1065
  });
1049
1066
  return acc;