@scallop-io/sui-scallop-sdk 1.5.2 → 2.0.0-alpha.1

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 (59) hide show
  1. package/dist/index.d.mts +446 -599
  2. package/dist/index.d.ts +446 -599
  3. package/dist/index.js +29 -60
  4. package/dist/index.mjs +6 -6
  5. package/package.json +1 -1
  6. package/src/builders/loyaltyProgramBuilder.ts +5 -3
  7. package/src/builders/oracle.ts +10 -24
  8. package/src/builders/referralBuilder.ts +5 -9
  9. package/src/builders/sCoinBuilder.ts +9 -8
  10. package/src/builders/spoolBuilder.ts +4 -6
  11. package/src/constants/common.ts +114 -126
  12. package/src/constants/index.ts +0 -5
  13. package/src/constants/pyth.ts +25 -34
  14. package/src/constants/queryKeys.ts +4 -2
  15. package/src/models/index.ts +1 -0
  16. package/src/models/scallop.ts +23 -19
  17. package/src/models/scallopAddress.ts +11 -8
  18. package/src/models/scallopBuilder.ts +32 -35
  19. package/src/models/scallopCache.ts +1 -1
  20. package/src/models/scallopClient.ts +87 -89
  21. package/src/models/scallopConstants.ts +341 -0
  22. package/src/models/scallopIndexer.ts +11 -24
  23. package/src/models/scallopQuery.ts +65 -70
  24. package/src/models/scallopUtils.ts +114 -244
  25. package/src/queries/borrowIncentiveQuery.ts +21 -56
  26. package/src/queries/borrowLimitQuery.ts +3 -6
  27. package/src/queries/coreQuery.ts +94 -112
  28. package/src/queries/flashloanFeeQuery.ts +86 -0
  29. package/src/queries/isolatedAssetQuery.ts +12 -11
  30. package/src/queries/poolAddressesQuery.ts +187 -112
  31. package/src/queries/portfolioQuery.ts +65 -67
  32. package/src/queries/priceQuery.ts +16 -22
  33. package/src/queries/sCoinQuery.ts +15 -16
  34. package/src/queries/spoolQuery.ts +49 -59
  35. package/src/queries/supplyLimitQuery.ts +2 -6
  36. package/src/queries/xOracleQuery.ts +4 -15
  37. package/src/types/address.ts +12 -18
  38. package/src/types/builder/borrowIncentive.ts +2 -3
  39. package/src/types/builder/core.ts +20 -27
  40. package/src/types/builder/index.ts +1 -2
  41. package/src/types/builder/referral.ts +4 -8
  42. package/src/types/builder/sCoin.ts +4 -8
  43. package/src/types/builder/spool.ts +7 -10
  44. package/src/types/constant/common.ts +43 -49
  45. package/src/types/constant/enum.ts +15 -27
  46. package/src/types/constant/xOracle.ts +3 -5
  47. package/src/types/model.ts +47 -28
  48. package/src/types/query/borrowIncentive.ts +7 -24
  49. package/src/types/query/core.ts +8 -18
  50. package/src/types/query/portfolio.ts +8 -17
  51. package/src/types/query/spool.ts +5 -11
  52. package/src/types/utils.ts +1 -21
  53. package/src/utils/core.ts +1 -1
  54. package/src/utils/query.ts +13 -20
  55. package/src/utils/util.ts +6 -84
  56. package/src/constants/coinGecko.ts +0 -34
  57. package/src/constants/enum.ts +0 -268
  58. package/src/constants/flashloan.ts +0 -18
  59. package/src/constants/poolAddress.ts +0 -898
@@ -1,8 +1,3 @@
1
- import type {
2
- SupportBorrowIncentiveCoins,
3
- SupportBorrowIncentiveRewardCoins,
4
- } from '../constant';
5
-
6
1
  export interface BorrowIncentiveAccountKey {
7
2
  id: string;
8
3
  onwerId: string;
@@ -13,12 +8,12 @@ type OptionalKeys<T> = {
13
8
  };
14
9
 
15
10
  export type BorrowIncentivePools = OptionalKeys<
16
- Record<SupportBorrowIncentiveCoins, BorrowIncentivePool>
11
+ Record<string, BorrowIncentivePool>
17
12
  >;
18
13
 
19
14
  export type BorrowIncentivePoolPoints = {
20
15
  symbol: string;
21
- coinName: SupportBorrowIncentiveRewardCoins;
16
+ coinName: string;
22
17
  coinType: string;
23
18
  coinDecimal: number;
24
19
  coinPrice: number;
@@ -31,7 +26,7 @@ export type BorrowIncentivePoolPoints = {
31
26
  CalculatedBorrowIncentivePoolPointData;
32
27
 
33
28
  export type BorrowIncentivePool = {
34
- coinName: SupportBorrowIncentiveCoins;
29
+ coinName: string;
35
30
  symbol: string;
36
31
  coinType: string;
37
32
  coinDecimal: number;
@@ -39,9 +34,7 @@ export type BorrowIncentivePool = {
39
34
  stakedAmount: number;
40
35
  stakedCoin: number;
41
36
  stakedValue: number;
42
- points: OptionalKeys<
43
- Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
44
- >;
37
+ points: OptionalKeys<Record<string, BorrowIncentivePoolPoints>>;
45
38
  };
46
39
 
47
40
  export type OriginBorrowIncentivePoolPointData = {
@@ -85,12 +78,7 @@ export type ParsedBorrowIncentivePoolPointData = {
85
78
 
86
79
  export type ParsedBorrowIncentivePoolData = {
87
80
  poolType: string;
88
- poolPoints: OptionalKeys<
89
- Record<
90
- SupportBorrowIncentiveRewardCoins,
91
- ParsedBorrowIncentivePoolPointData
92
- >
93
- >;
81
+ poolPoints: OptionalKeys<Record<string, ParsedBorrowIncentivePoolPointData>>;
94
82
  minStakes: number;
95
83
  maxStakes: number;
96
84
  staked: number;
@@ -110,7 +98,7 @@ export type CalculatedBorrowIncentivePoolPointData = {
110
98
  };
111
99
 
112
100
  export type BorrowIncentiveAccounts = OptionalKeys<
113
- Record<SupportBorrowIncentiveCoins, ParsedBorrowIncentiveAccountData>
101
+ Record<string, ParsedBorrowIncentiveAccountData>
114
102
  >;
115
103
 
116
104
  export type OriginBorrowIncentiveAccountPoolData = {
@@ -140,12 +128,7 @@ export type ParsedBorrowIncentiveAccountPoolData = {
140
128
  };
141
129
 
142
130
  export type ParsedBorrowIncentiveAccountData = {
143
- pointList: OptionalKeys<
144
- Record<
145
- SupportBorrowIncentiveRewardCoins,
146
- ParsedBorrowIncentiveAccountPoolData
147
- >
148
- >;
131
+ pointList: OptionalKeys<Record<string, ParsedBorrowIncentiveAccountPoolData>>;
149
132
  poolType: string;
150
133
  debtAmount: number;
151
134
  };
@@ -1,25 +1,15 @@
1
- import type {
2
- SupportPoolCoins,
3
- SupportCollateralCoins,
4
- SupportMarketCoins,
5
- CoinWrappedType,
6
- SupportSCoin,
7
- } from '../constant';
1
+ import type { CoinWrappedType } from '../constant';
8
2
 
9
3
  type OptionalKeys<T> = {
10
4
  [K in keyof T]?: T[K];
11
5
  };
12
6
 
13
- export type MarketPools = OptionalKeys<Record<SupportPoolCoins, MarketPool>>;
14
- export type MarketCollaterals = OptionalKeys<
15
- Record<SupportCollateralCoins, MarketCollateral>
16
- >;
17
- export type CoinAmounts = OptionalKeys<Record<SupportPoolCoins, number>>;
18
- export type MarketCoinAmounts = OptionalKeys<
19
- Record<SupportMarketCoins, number>
20
- >;
7
+ export type MarketPools = OptionalKeys<Record<string, MarketPool>>;
8
+ export type MarketCollaterals = OptionalKeys<Record<string, MarketCollateral>>;
9
+ export type CoinAmounts = OptionalKeys<Record<string, number>>;
10
+ export type MarketCoinAmounts = OptionalKeys<Record<string, number>>;
21
11
 
22
- export type SCoinAmounts = OptionalKeys<Record<SupportSCoin, number>>;
12
+ export type SCoinAmounts = OptionalKeys<Record<string, number>>;
23
13
 
24
14
  export type BalanceSheet = {
25
15
  cash: string;
@@ -123,7 +113,7 @@ export type RiskModel = {
123
113
  export type CollateralStat = { amount: string };
124
114
 
125
115
  export type MarketPool = {
126
- coinName: SupportPoolCoins;
116
+ coinName: string;
127
117
  symbol: string;
128
118
  coinType: string;
129
119
  marketCoinType: string;
@@ -149,7 +139,7 @@ export type MarketPool = {
149
139
  CalculatedMarketPoolData;
150
140
 
151
141
  export type MarketCollateral = {
152
- coinName: SupportCollateralCoins;
142
+ coinName: string;
153
143
  symbol: string;
154
144
  coinType: string;
155
145
  marketCoinType: string;
@@ -1,16 +1,11 @@
1
1
  import type { MarketPool } from './core';
2
2
  import type { Spool } from './spool';
3
- import type {
4
- SupportPoolCoins,
5
- SupportCollateralCoins,
6
- SupportBorrowIncentiveRewardCoins,
7
- } from '../constant';
8
3
 
9
4
  type OptionalKeys<T> = {
10
5
  [K in keyof T]?: T[K];
11
6
  };
12
7
 
13
- export type Lendings = OptionalKeys<Record<SupportPoolCoins, Lending>>;
8
+ export type Lendings = OptionalKeys<Record<string, Lending>>;
14
9
  export type ObligationAccounts = OptionalKeys<
15
10
  Record<string, ObligationAccount>
16
11
  >;
@@ -72,17 +67,13 @@ export type ObligationAccount = {
72
67
  totalDepositedPools: number;
73
68
  totalBorrowedPools: number;
74
69
  totalRewardedPools: number;
75
- collaterals: OptionalKeys<
76
- Record<SupportCollateralCoins, ObligationCollateral>
77
- >;
78
- debts: OptionalKeys<Record<SupportPoolCoins, ObligationDebt>>;
79
- borrowIncentives: OptionalKeys<
80
- Record<SupportPoolCoins, ObligationBorrowIncentive>
81
- >;
70
+ collaterals: OptionalKeys<Record<string, ObligationCollateral>>;
71
+ debts: OptionalKeys<Record<string, ObligationDebt>>;
72
+ borrowIncentives: OptionalKeys<Record<string, ObligationBorrowIncentive>>;
82
73
  };
83
74
 
84
75
  export type ObligationCollateral = {
85
- coinName: SupportCollateralCoins;
76
+ coinName: string;
86
77
  coinType: string;
87
78
  symbol: string;
88
79
  coinDecimal: number;
@@ -99,7 +90,7 @@ export type ObligationCollateral = {
99
90
  };
100
91
 
101
92
  export type ObligationDebt = {
102
- coinName: SupportPoolCoins;
93
+ coinName: string;
103
94
  coinType: string;
104
95
  symbol: string;
105
96
  coinDecimal: number;
@@ -118,7 +109,7 @@ export type ObligationDebt = {
118
109
  };
119
110
 
120
111
  export type ObligationBorrowIcentiveReward = {
121
- coinName: SupportBorrowIncentiveRewardCoins;
112
+ coinName: string;
122
113
  coinType: string;
123
114
  symbol: string;
124
115
  coinDecimal: number;
@@ -129,7 +120,7 @@ export type ObligationBorrowIcentiveReward = {
129
120
  };
130
121
 
131
122
  export type ObligationBorrowIncentive = {
132
- coinName: SupportPoolCoins;
123
+ coinName: string;
133
124
  coinType: string;
134
125
  symbol: string;
135
126
  coinDecimal: number;
@@ -1,13 +1,11 @@
1
- import type { SupportStakeMarketCoins } from '../constant';
2
-
3
1
  type OptionalKeys<T> = {
4
2
  [K in keyof T]?: T[K];
5
3
  };
6
4
 
7
- export type Spools = OptionalKeys<Record<SupportStakeMarketCoins, Spool>>;
5
+ export type Spools = OptionalKeys<Record<string, Spool>>;
8
6
 
9
7
  export type Spool = {
10
- marketCoinName: SupportStakeMarketCoins;
8
+ marketCoinName: string;
11
9
  symbol: string;
12
10
  coinType: string;
13
11
  marketCoinType: string;
@@ -121,13 +119,9 @@ export type CalculatedSpoolRewardPoolData = {
121
119
  rewardPerSec: number;
122
120
  };
123
121
 
124
- export type StakePools = OptionalKeys<
125
- Record<SupportStakeMarketCoins, StakePool>
126
- >;
127
- export type StakeRewardPools = OptionalKeys<
128
- Record<SupportStakeMarketCoins, StakeRewardPool>
129
- >;
130
- export type StakeAccounts = Record<SupportStakeMarketCoins, StakeAccount[]>;
122
+ export type StakePools = OptionalKeys<Record<string, StakePool>>;
123
+ export type StakeRewardPools = OptionalKeys<Record<string, StakeRewardPool>>;
124
+ export type StakeAccounts = Record<string, StakeAccount[]>;
131
125
 
132
126
  export interface StakeAccount {
133
127
  id: string;
@@ -1,25 +1,5 @@
1
- import type { SupportCoins } from './constant';
2
-
3
1
  export type OptionalKeys<T> = {
4
2
  [K in keyof T]?: T[K];
5
3
  };
6
4
 
7
- export type CoinPrices = OptionalKeys<Record<SupportCoins, number>>;
8
-
9
- export type PoolAddressInfo = {
10
- name: string;
11
- coingeckoId: string;
12
- decimal: number;
13
- pythFeedId: string;
14
- lendingPoolAddress?: string;
15
- collateralPoolAddress?: string; // not all pool has collateral
16
- borrowDynamic?: string;
17
- interestModelId?: string;
18
- borrowFeeKey?: string;
19
- supplyLimitKey?: string;
20
- borrowLimitKey?: string;
21
- isolatedAssetKey?: string;
22
- sCoinAddress: string | undefined;
23
- marketCoinAddress: string;
24
- sCoinName: string | undefined;
25
- };
5
+ export type CoinPrices = OptionalKeys<Record<string, number>>;
package/src/utils/core.ts CHANGED
@@ -2,7 +2,7 @@ import { SuiObjectData } from '@mysten/sui/client';
2
2
 
3
3
  export const parseObjectAs = <T>(object: SuiObjectData): T => {
4
4
  if (!(object && object.content && 'fields' in object.content))
5
- throw new Error(`Failed to parse object`);
5
+ throw new Error(`Failed to parse object ${object}`);
6
6
 
7
7
  const fields = object.content.fields as any;
8
8
 
@@ -18,14 +18,11 @@ import type {
18
18
  ParsedBorrowIncentivePoolData,
19
19
  OriginBorrowIncentiveAccountData,
20
20
  ParsedBorrowIncentiveAccountData,
21
- SupportPoolCoins,
22
- SupportCollateralCoins,
23
21
  OriginBorrowIncentivePoolPointData,
24
22
  ParsedBorrowIncentivePoolPointData,
25
23
  CalculatedBorrowIncentivePoolPointData,
26
24
  OriginBorrowIncentiveAccountPoolData,
27
25
  ParsedBorrowIncentiveAccountPoolData,
28
- SupportBorrowIncentiveRewardCoins,
29
26
  } from '../types';
30
27
 
31
28
  /**
@@ -72,10 +69,13 @@ export const calculateMarketPoolData = (
72
69
  utils: ScallopUtils,
73
70
  parsedMarketPoolData: ParsedMarketPoolData
74
71
  ): CalculatedMarketPoolData => {
75
- const poolCoinName = utils.parseCoinNameFromType<SupportPoolCoins>(
72
+ const poolCoinName = utils.parseCoinNameFromType(
76
73
  parsedMarketPoolData.coinType
77
74
  );
75
+
78
76
  const coinDecimal = utils.getCoinDecimal(poolCoinName);
77
+ if (coinDecimal === undefined)
78
+ throw new Error(`Coin decimal not found for ${poolCoinName}`);
79
79
 
80
80
  const borrowYearFactor = 24 * 365 * 3600;
81
81
 
@@ -210,11 +210,12 @@ export const calculateMarketCollateralData = (
210
210
  utils: ScallopUtils,
211
211
  parsedMarketCollateralData: ParsedMarketCollateralData
212
212
  ): CalculatedMarketCollateralData => {
213
- const collateralCoinName =
214
- utils.parseCoinNameFromType<SupportCollateralCoins>(
215
- parsedMarketCollateralData.coinType
216
- );
213
+ const collateralCoinName = utils.parseCoinNameFromType(
214
+ parsedMarketCollateralData.coinType
215
+ );
217
216
  const coinDecimal = utils.getCoinDecimal(collateralCoinName);
217
+ if (coinDecimal === undefined)
218
+ throw new Error(`Coin decimal not found for ${collateralCoinName}`);
218
219
 
219
220
  const maxCollateralCoin = BigNumber(
220
221
  parsedMarketCollateralData.maxCollateralAmount
@@ -448,17 +449,12 @@ export const parseOriginBorrowIncentivePoolData = (
448
449
  poolPoints: originBorrowIncentivePoolData.points.reduce(
449
450
  (acc, point) => {
450
451
  const parsed = parseOriginBorrowIncentivesPoolPointData(point);
451
- const name = utils.parseSCoinTypeNameToMarketCoinName(
452
- parseStructTag(parsed.pointType).name.toLowerCase()
453
- ) as SupportBorrowIncentiveRewardCoins;
452
+ const name = utils.parseCoinNameFromType(parsed.pointType) as string;
454
453
 
455
454
  acc[name] = parsed;
456
455
  return acc;
457
456
  },
458
- {} as Record<
459
- SupportBorrowIncentiveRewardCoins,
460
- ParsedBorrowIncentivePoolPointData
461
- >
457
+ {} as Record<string, ParsedBorrowIncentivePoolPointData>
462
458
  ),
463
459
  };
464
460
  };
@@ -597,14 +593,11 @@ export const parseOriginBorrowIncentiveAccountData = (
597
593
  const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
598
594
  const name = parseStructTag(
599
595
  parsed.pointType
600
- ).name.toLowerCase() as SupportBorrowIncentiveRewardCoins;
596
+ ).name.toLowerCase() as string;
601
597
  acc[name] = parsed;
602
598
  return acc;
603
599
  },
604
- {} as Record<
605
- SupportBorrowIncentiveRewardCoins,
606
- ParsedBorrowIncentiveAccountPoolData
607
- >
600
+ {} as Record<string, ParsedBorrowIncentiveAccountPoolData>
608
601
  ),
609
602
  };
610
603
  };
package/src/utils/util.ts CHANGED
@@ -1,85 +1,6 @@
1
1
  import type { PriceFeed } from '@pythnetwork/pyth-sui-js';
2
- import {
3
- SUPPORT_POOLS,
4
- SUPPORT_COLLATERALS,
5
- SUPPORT_SPOOLS_REWARDS,
6
- MAX_LOCK_DURATION,
7
- SUPPORT_BORROW_INCENTIVE_REWARDS,
8
- SUPPORT_SCOIN,
9
- SUPPORT_SUI_BRIDGE,
10
- SUPPORT_WORMHOLE,
11
- } from '../constants';
12
- import type { ScallopAddress } from '../models';
13
- import type {
14
- SupportAssetCoins,
15
- SupportCoins,
16
- SupportMarketCoins,
17
- SupportSCoin,
18
- SupportSuiBridgeCoins,
19
- SupportWormholeCoins,
20
- } from '../types';
21
-
22
- const COIN_SET = Array.from(
23
- new Set([
24
- ...SUPPORT_POOLS,
25
- ...SUPPORT_COLLATERALS,
26
- ...SUPPORT_SPOOLS_REWARDS,
27
- ...SUPPORT_BORROW_INCENTIVE_REWARDS,
28
- ...SUPPORT_SCOIN,
29
- ])
30
- );
31
-
32
- export const isMarketCoin = (
33
- coinName: SupportCoins
34
- ): coinName is SupportMarketCoins | SupportSCoin => {
35
- const assetCoinName = coinName.slice(1).toLowerCase() as SupportAssetCoins;
36
- return (
37
- coinName.charAt(0).toLowerCase() === 's' && COIN_SET.includes(assetCoinName)
38
- );
39
- };
40
-
41
- export const isSuiBridgeAsset = (
42
- coinName: any
43
- ): coinName is SupportSuiBridgeCoins => {
44
- return SUPPORT_SUI_BRIDGE.includes(coinName);
45
- };
46
-
47
- export const isWormholeAsset = (
48
- coinName: any
49
- ): coinName is SupportWormholeCoins => {
50
- return SUPPORT_WORMHOLE.includes(coinName);
51
- };
52
-
53
- export const parseAssetSymbol = (coinName: SupportCoins): string => {
54
- if (isWormholeAsset(coinName)) {
55
- return `w${coinName.slice(1).toUpperCase()}`;
56
- }
57
- if (isSuiBridgeAsset(coinName)) {
58
- switch (coinName) {
59
- case 'sbwbtc':
60
- return 'sbwBTC';
61
- default: {
62
- return `sb${coinName.slice(2).toUpperCase()}`;
63
- }
64
- }
65
- }
66
- if (isMarketCoin(coinName)) {
67
- const assetCoinName = coinName.slice(1).toLowerCase() as SupportAssetCoins;
68
- return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
69
- }
70
- switch (coinName) {
71
- case 'afsui':
72
- return 'afSUI';
73
- case 'hasui':
74
- return 'haSUI';
75
- case 'vsui':
76
- return 'vSUI';
77
- case 'musd':
78
- return 'mUSD';
79
- default:
80
- return coinName.toUpperCase();
81
- }
82
- };
2
+ import { MAX_LOCK_DURATION } from 'src/constants';
3
+ import { ScallopConstants } from 'src/models/scallopConstants';
83
4
 
84
5
  /**
85
6
  * Parse price from pyth price feed.
@@ -90,12 +11,13 @@ export const parseAssetSymbol = (coinName: SupportCoins): string => {
90
11
  */
91
12
  export const parseDataFromPythPriceFeed = (
92
13
  feed: PriceFeed,
93
- address: ScallopAddress
14
+ constants: ScallopConstants
94
15
  ) => {
95
- const assetCoinNames = COIN_SET as SupportAssetCoins[];
16
+ const assetCoinNames = [...constants.whitelist.lending] as string[];
96
17
  const assetCoinName = assetCoinNames.find((assetCoinName) => {
97
18
  return (
98
- address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`) === feed.id
19
+ constants.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`) ===
20
+ feed.id
99
21
  );
100
22
  });
101
23
  if (assetCoinName) {
@@ -1,34 +0,0 @@
1
- import { SupportPoolCoins } from 'src/types/constant/common';
2
-
3
- export const COIN_GECKGO_IDS: Record<SupportPoolCoins, string> = {
4
- // Sui Bridge
5
- sbeth: 'ethereum',
6
- sbusdt: 'tether',
7
- sbwbtc: 'bitcoin',
8
- // Wormhole
9
- weth: 'ethereum',
10
- wbtc: 'bitcoin',
11
- wusdc: 'usdc',
12
- wusdt: 'tether',
13
- wapt: 'aptos',
14
- wsol: 'solana',
15
- // Sui Native
16
- usdc: 'usdc',
17
- // Sui LST
18
- sui: 'sui',
19
- afsui: 'sui',
20
- hasui: 'sui',
21
- vsui: 'sui',
22
- // Stable
23
- fdusd: 'first-digital-usd',
24
- // DeFi
25
- cetus: 'cetus-protocol',
26
- sca: 'scallop-2',
27
- deep: 'deepbook',
28
- // Isolated Asset
29
- fud: 'fud-the-pug',
30
- blub: 'blub',
31
- musd: 'meta-usd',
32
- ns: 'suins-token',
33
- usdy: 'ondo-us-dollar-yield',
34
- };