@scallop-io/sui-scallop-sdk 1.4.7 → 1.4.8

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.
@@ -353,6 +353,7 @@ export declare class ScallopQuery {
353
353
  getLendings(poolCoinNames?: SupportPoolCoins[], ownerAddress?: string, args?: {
354
354
  indexer?: boolean;
355
355
  marketPools?: MarketPools;
356
+ coinPrices?: CoinPrices;
356
357
  }): Promise<{
357
358
  usdc?: import("../types").Lending | undefined;
358
359
  sbeth?: import("../types").Lending | undefined;
@@ -399,6 +400,7 @@ export declare class ScallopQuery {
399
400
  collaterals: MarketCollaterals;
400
401
  pools: MarketPools;
401
402
  };
403
+ coinPrices?: CoinPrices;
402
404
  }): Promise<{
403
405
  [x: string]: import("../types").ObligationAccount | undefined;
404
406
  }>;
@@ -595,54 +597,60 @@ export declare class ScallopQuery {
595
597
  walletAddress?: string;
596
598
  indexer?: boolean;
597
599
  }): Promise<{
600
+ totalLockedScaValue: number;
598
601
  lendings: {
599
- totalSupplyValue: number;
600
- suppliedPools: {
601
- suppliedCoin: number;
602
- suppliedValue: number;
603
- stakedCoin: number;
602
+ suppliedCoin: number;
603
+ suppliedValue: number;
604
+ stakedCoin: number;
605
+ coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd";
606
+ symbol: string;
607
+ coinType: string;
608
+ coinPrice: number;
609
+ coinDecimals: number;
610
+ supplyApr: number;
611
+ supplyApy: number;
612
+ incentiveApr: number;
613
+ }[];
614
+ borrowings: {
615
+ obligationId: string;
616
+ totalDebtsInUsd: number;
617
+ totalCollateralInUsd: number;
618
+ riskLevel: number;
619
+ availableCollateralInUsd: number;
620
+ totalUnhealthyCollateralInUsd: number;
621
+ borrowedPools: {
604
622
  coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd";
605
623
  symbol: string;
624
+ coinDecimals: number;
606
625
  coinType: string;
607
626
  coinPrice: number;
608
- coinDecimals: number;
609
- supplyApr: number;
610
- supplyApy: number;
611
- incentiveApr: number;
612
- }[];
613
- };
614
- borrowings: {
615
- obligations: {
616
- obligationId: string;
617
- totalDebtsInUsd: number;
618
- totalCollateralInUsd: number;
619
- riskLevel: number;
620
- availableCollateralInUsd: number;
621
- totalUnhealthyCollateralInUsd: number;
622
- borrowedPools: {
623
- coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd";
627
+ borrowedCoin: number;
628
+ borrowedValueInUsd: number;
629
+ borrowApr: number | undefined;
630
+ borrowApy: number | undefined;
631
+ incentiveInfos: {
632
+ coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd" | "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep" | "sfdusd";
624
633
  symbol: string;
625
- coinDecimals: number;
626
634
  coinType: string;
627
- coinPrice: number;
628
- borrowedCoin: number;
629
- borrowedValueInUsd: number;
630
- borrowApr: number | undefined;
631
- borrowApy: number | undefined;
632
- incentiveInfos: {
633
- coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd" | "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep" | "sfdusd";
634
- symbol: string;
635
- coinType: string;
636
- incentiveApr: number;
637
- }[];
635
+ incentiveApr: number;
638
636
  }[];
639
637
  }[];
640
- totalDebtValue: number;
641
- totalCollateralValue: number;
642
- };
638
+ }[];
643
639
  pendingRewards: {
644
640
  lendings: any;
645
641
  borrowIncentives: any;
646
642
  };
643
+ veScas: {
644
+ veScaKey: string;
645
+ coinPrice: number;
646
+ lockedScaInCoin: number;
647
+ lockedScaInUsd: number;
648
+ currentVeScaBalance: number;
649
+ remainingLockPeriodInDays: number;
650
+ unlockAt: number;
651
+ }[];
652
+ totalDebtValue: number;
653
+ totalCollateralValue: number;
654
+ totalSupplyValue: number;
647
655
  }>;
648
656
  }
@@ -10,7 +10,7 @@ import { SuiObjectRef } from '@mysten/sui/client';
10
10
  * @param indexer - Whether to use indexer.
11
11
  * @return User lending infomation for specific pools.
12
12
  */
13
- export declare const getLendings: (query: ScallopQuery, poolCoinNames?: SupportPoolCoins[], ownerAddress?: string, marketPools?: MarketPools, indexer?: boolean) => Promise<{
13
+ export declare const getLendings: (query: ScallopQuery, poolCoinNames?: SupportPoolCoins[], ownerAddress?: string, marketPools?: MarketPools, coinPrices?: CoinPrices, indexer?: boolean) => Promise<{
14
14
  usdc?: Lending | undefined;
15
15
  sbeth?: Lending | undefined;
16
16
  weth?: Lending | undefined;
@@ -58,7 +58,7 @@ export declare const getLending: (query: ScallopQuery, poolCoinName: SupportPool
58
58
  export declare const getObligationAccounts: (query: ScallopQuery, ownerAddress?: string, market?: {
59
59
  pools: MarketPools;
60
60
  collaterals: MarketCollaterals;
61
- }, indexer?: boolean) => Promise<{
61
+ }, coinPrices?: CoinPrices, indexer?: boolean) => Promise<{
62
62
  [x: string]: ObligationAccount | undefined;
63
63
  }>;
64
64
  /**
@@ -82,53 +82,59 @@ export declare const getTotalValueLocked: (query: ScallopQuery, indexer?: boolea
82
82
  * Get user portfolio by wallet address
83
83
  */
84
84
  export declare const getUserPortfolio: (query: ScallopQuery, walletAddress: string, indexer?: boolean) => Promise<{
85
+ totalLockedScaValue: number;
85
86
  lendings: {
86
- totalSupplyValue: number;
87
- suppliedPools: {
88
- suppliedCoin: number;
89
- suppliedValue: number;
90
- stakedCoin: number;
87
+ suppliedCoin: number;
88
+ suppliedValue: number;
89
+ stakedCoin: number;
90
+ coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd";
91
+ symbol: string;
92
+ coinType: string;
93
+ coinPrice: number;
94
+ coinDecimals: number;
95
+ supplyApr: number;
96
+ supplyApy: number;
97
+ incentiveApr: number;
98
+ }[];
99
+ borrowings: {
100
+ obligationId: string;
101
+ totalDebtsInUsd: number;
102
+ totalCollateralInUsd: number;
103
+ riskLevel: number;
104
+ availableCollateralInUsd: number;
105
+ totalUnhealthyCollateralInUsd: number;
106
+ borrowedPools: {
91
107
  coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd";
92
108
  symbol: string;
109
+ coinDecimals: number;
93
110
  coinType: string;
94
111
  coinPrice: number;
95
- coinDecimals: number;
96
- supplyApr: number;
97
- supplyApy: number;
98
- incentiveApr: number;
99
- }[];
100
- };
101
- borrowings: {
102
- obligations: {
103
- obligationId: string;
104
- totalDebtsInUsd: number;
105
- totalCollateralInUsd: number;
106
- riskLevel: number;
107
- availableCollateralInUsd: number;
108
- totalUnhealthyCollateralInUsd: number;
109
- borrowedPools: {
110
- coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd";
112
+ borrowedCoin: number;
113
+ borrowedValueInUsd: number;
114
+ borrowApr: number | undefined;
115
+ borrowApy: number | undefined;
116
+ incentiveInfos: {
117
+ coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd" | "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep" | "sfdusd";
111
118
  symbol: string;
112
- coinDecimals: number;
113
119
  coinType: string;
114
- coinPrice: number;
115
- borrowedCoin: number;
116
- borrowedValueInUsd: number;
117
- borrowApr: number | undefined;
118
- borrowApy: number | undefined;
119
- incentiveInfos: {
120
- coinName: "usdc" | "sbeth" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd" | "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep" | "sfdusd";
121
- symbol: string;
122
- coinType: string;
123
- incentiveApr: number;
124
- }[];
120
+ incentiveApr: number;
125
121
  }[];
126
122
  }[];
127
- totalDebtValue: number;
128
- totalCollateralValue: number;
129
- };
123
+ }[];
130
124
  pendingRewards: {
131
125
  lendings: any;
132
126
  borrowIncentives: any;
133
127
  };
128
+ veScas: {
129
+ veScaKey: string;
130
+ coinPrice: number;
131
+ lockedScaInCoin: number;
132
+ lockedScaInUsd: number;
133
+ currentVeScaBalance: number;
134
+ remainingLockPeriodInDays: number;
135
+ unlockAt: number;
136
+ }[];
137
+ totalDebtValue: number;
138
+ totalCollateralValue: number;
139
+ totalSupplyValue: number;
134
140
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -577,13 +577,18 @@ export class ScallopQuery {
577
577
  public async getLendings(
578
578
  poolCoinNames?: SupportPoolCoins[],
579
579
  ownerAddress: string = this.walletAddress,
580
- args?: { indexer?: boolean; marketPools?: MarketPools }
580
+ args?: {
581
+ indexer?: boolean;
582
+ marketPools?: MarketPools;
583
+ coinPrices?: CoinPrices;
584
+ }
581
585
  ) {
582
586
  return await getLendings(
583
587
  this,
584
588
  poolCoinNames,
585
589
  ownerAddress,
586
590
  args?.marketPools,
591
+ args?.coinPrices,
587
592
  args?.indexer
588
593
  );
589
594
  }
@@ -622,12 +627,14 @@ export class ScallopQuery {
622
627
  collaterals: MarketCollaterals;
623
628
  pools: MarketPools;
624
629
  };
630
+ coinPrices?: CoinPrices;
625
631
  }
626
632
  ) {
627
633
  return await getObligationAccounts(
628
634
  this,
629
635
  ownerAddress,
630
636
  args?.market,
637
+ args?.coinPrices,
631
638
  args?.indexer
632
639
  );
633
640
  }
@@ -141,7 +141,7 @@ export const getAllAddresses = async (query: ScallopQuery) => {
141
141
  sCoinTreasury,
142
142
  sCoinType,
143
143
  coinDecimalId,
144
- coinType,
144
+ coinType: `0x${coinType}`,
145
145
  };
146
146
 
147
147
  await new Promise((resolve) => setTimeout(resolve, 200));
@@ -47,6 +47,7 @@ export const getLendings = async (
47
47
  poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
48
48
  ownerAddress?: string,
49
49
  marketPools?: MarketPools,
50
+ coinPrices?: CoinPrices,
50
51
  indexer: boolean = false
51
52
  ) => {
52
53
  const marketCoinNames = poolCoinNames.map((poolCoinName) =>
@@ -56,7 +57,7 @@ export const getLendings = async (
56
57
  (SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
57
58
  ) as SupportStakeMarketCoins[];
58
59
 
59
- const coinPrices = await query.utils.getCoinPrices();
60
+ coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
60
61
  marketPools =
61
62
  marketPools ??
62
63
  (
@@ -321,12 +322,15 @@ export const getObligationAccounts = async (
321
322
  pools: MarketPools;
322
323
  collaterals: MarketCollaterals;
323
324
  },
325
+ coinPrices?: CoinPrices,
324
326
  indexer: boolean = false
325
327
  ) => {
326
328
  market = market ?? (await query.getMarketPools(undefined, { indexer }));
327
- const coinPrices = await query.getAllCoinPrices({
328
- marketPools: market.pools,
329
- });
329
+ coinPrices =
330
+ coinPrices ??
331
+ (await query.getAllCoinPrices({
332
+ marketPools: market.pools,
333
+ }));
330
334
  const [coinAmounts, obligations] = await Promise.all([
331
335
  query.getCoinAmounts(undefined, ownerAddress),
332
336
  query.getObligations(ownerAddress),
@@ -856,20 +860,26 @@ export const getUserPortfolio = async (
856
860
  walletAddress: string,
857
861
  indexer: boolean = false
858
862
  ) => {
859
- const market = await query.getMarketPools();
860
- const [lendings, obligationAccounts, borrowIncentivePools] =
863
+ const coinPrices = await query.utils.getCoinPrices();
864
+ const market = await query.getMarketPools(undefined, { indexer, coinPrices });
865
+
866
+ const [lendings, obligationAccounts, borrowIncentivePools, veScas] =
861
867
  await Promise.all([
862
868
  query.getLendings(undefined, walletAddress, {
863
869
  indexer,
864
870
  marketPools: market.pools,
871
+ coinPrices,
865
872
  }),
866
873
  query.getObligationAccounts(walletAddress, {
867
874
  indexer,
868
875
  market: market,
876
+ coinPrices,
869
877
  }),
870
878
  query.getBorrowIncentivePools(undefined, {
871
879
  marketPools: market.pools,
880
+ coinPrices,
872
881
  }),
882
+ query.getVeScas({ walletAddress, excludeEmpty: true }),
873
883
  ]);
874
884
 
875
885
  // get pending rewards (spool and borrow incentive)
@@ -988,31 +998,45 @@ export const getUserPortfolio = async (
988
998
  }
989
999
  >
990
1000
  );
1001
+
1002
+ const parsedVeScas = veScas.map(
1003
+ ({ keyId, lockedScaCoin, currentVeScaBalance, unlockAt }) => ({
1004
+ veScaKey: keyId,
1005
+ coinPrice: coinPrices.sca ?? 0,
1006
+ lockedScaInCoin: lockedScaCoin,
1007
+ lockedScaInUsd: lockedScaCoin * (coinPrices.sca ?? 0),
1008
+ currentVeScaBalance,
1009
+ remainingLockPeriodInDays:
1010
+ unlockAt - Date.now() > 0 ? (unlockAt - Date.now()) / 86400000 : 0,
1011
+ unlockAt,
1012
+ })
1013
+ );
1014
+
991
1015
  return {
992
- lendings: {
993
- totalSupplyValue: parsedLendings.reduce((acc, curr) => {
994
- acc += curr.suppliedValue;
1016
+ totalSupplyValue: parsedLendings.reduce((acc, curr) => {
1017
+ acc += curr.suppliedValue;
1018
+ return acc;
1019
+ }, 0),
1020
+ ...parsedObligationAccounts.reduce(
1021
+ (acc, curr) => {
1022
+ acc.totalDebtValue += curr.totalDebtsInUsd;
1023
+ acc.totalCollateralValue += curr.totalCollateralInUsd;
995
1024
  return acc;
996
- }, 0),
997
- suppliedPools: parsedLendings,
998
- },
999
- borrowings: {
1000
- ...parsedObligationAccounts.reduce(
1001
- (acc, curr) => {
1002
- acc.totalDebtValue += curr.totalDebtsInUsd;
1003
- acc.totalCollateralValue += curr.totalCollateralInUsd;
1004
- return acc;
1005
- },
1006
- {
1007
- totalDebtValue: 0,
1008
- totalCollateralValue: 0,
1009
- } as {
1010
- totalDebtValue: number;
1011
- totalCollateralValue: number;
1012
- }
1013
- ),
1014
- obligations: parsedObligationAccounts,
1015
- },
1025
+ },
1026
+ {
1027
+ totalDebtValue: 0,
1028
+ totalCollateralValue: 0,
1029
+ } as {
1030
+ totalDebtValue: number;
1031
+ totalCollateralValue: number;
1032
+ }
1033
+ ),
1034
+ totalLockedScaValue: parsedVeScas.reduce((acc, curr) => {
1035
+ acc += curr.lockedScaInUsd;
1036
+ return acc;
1037
+ }, 0),
1038
+ lendings: parsedLendings,
1039
+ borrowings: parsedObligationAccounts,
1016
1040
  pendingRewards: {
1017
1041
  lendings: Object.entries(pendingLendingRewards).reduce(
1018
1042
  (acc, [key, value]) => {
@@ -1037,5 +1061,6 @@ export const getUserPortfolio = async (
1037
1061
  [] as any
1038
1062
  ),
1039
1063
  },
1064
+ veScas: parsedVeScas,
1040
1065
  };
1041
1066
  };