@scallop-io/sui-scallop-sdk 2.0.13-merge-split-ve-sca-alpha.5 → 2.1.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 (55) hide show
  1. package/dist/index.d.mts +622 -697
  2. package/dist/index.d.ts +622 -697
  3. package/dist/index.js +32 -33
  4. package/dist/index.mjs +10 -10
  5. package/package.json +8 -18
  6. package/src/builders/borrowIncentiveBuilder.ts +9 -21
  7. package/src/builders/coreBuilder.ts +2 -2
  8. package/src/builders/index.ts +2 -2
  9. package/src/builders/oracles/index.ts +2 -3
  10. package/src/builders/oracles/pyth.ts +2 -2
  11. package/src/builders/spoolBuilder.ts +2 -2
  12. package/src/builders/vescaBuilder.ts +14 -132
  13. package/src/constants/queryKeys.ts +29 -54
  14. package/src/constants/testAddress.ts +6 -12
  15. package/src/index.ts +11 -1
  16. package/src/models/index.ts +11 -9
  17. package/src/models/interface.ts +36 -0
  18. package/src/models/scallop.ts +38 -133
  19. package/src/models/scallopAddress.ts +127 -142
  20. package/src/models/scallopAxios.ts +185 -0
  21. package/src/models/scallopBuilder.ts +45 -75
  22. package/src/models/scallopClient.ts +124 -154
  23. package/src/models/scallopConstants.ts +248 -323
  24. package/src/models/scallopIndexer.ts +54 -98
  25. package/src/models/scallopQuery.ts +145 -190
  26. package/src/models/scallopQueryClient.ts +29 -0
  27. package/src/models/scallopSuiKit.ts +432 -0
  28. package/src/models/scallopUtils.ts +260 -164
  29. package/src/queries/borrowIncentiveQuery.ts +28 -16
  30. package/src/queries/borrowLimitQuery.ts +1 -1
  31. package/src/queries/coreQuery.ts +148 -107
  32. package/src/queries/flashloanFeeQuery.ts +12 -6
  33. package/src/queries/index.ts +0 -1
  34. package/src/queries/isolatedAssetQuery.ts +3 -3
  35. package/src/queries/loyaltyProgramQuery.ts +10 -8
  36. package/src/queries/ownerQuery.ts +32 -0
  37. package/src/queries/portfolioQuery.ts +4 -5
  38. package/src/queries/priceQuery.ts +14 -8
  39. package/src/queries/referralQuery.ts +9 -3
  40. package/src/queries/sCoinQuery.ts +4 -4
  41. package/src/queries/spoolQuery.ts +11 -11
  42. package/src/queries/supplyLimitQuery.ts +1 -1
  43. package/src/queries/switchboardQuery.ts +1 -1
  44. package/src/queries/vescaQuery.ts +31 -27
  45. package/src/queries/xOracleQuery.ts +13 -8
  46. package/src/types/address.ts +0 -3
  47. package/src/types/builder/core.ts +1 -1
  48. package/src/types/builder/vesca.ts +10 -20
  49. package/src/types/constant/queryKeys.ts +48 -0
  50. package/src/types/index.ts +0 -1
  51. package/src/utils/builder.ts +1 -1
  52. package/src/utils/util.ts +1 -33
  53. package/src/models/scallopCache.ts +0 -428
  54. package/src/queries/objectsQuery.ts +0 -18
  55. package/src/types/model.ts +0 -117
@@ -1,54 +1,27 @@
1
- import axios, { AxiosInstance } from 'axios';
2
- import { SDK_API_BASE_URL } from 'src/constants';
3
- import type {
1
+ import {
2
+ BorrowIncentivePool,
3
+ BorrowIncentivePoolPoints,
4
+ BorrowIncentivePools,
4
5
  Market,
5
- MarketPools,
6
- MarketPool,
7
- MarketCollaterals,
8
6
  MarketCollateral,
9
- Spools,
7
+ MarketCollaterals,
8
+ MarketPool,
9
+ MarketPools,
10
10
  Spool,
11
- BorrowIncentivePools,
12
- BorrowIncentivePool,
11
+ Spools,
13
12
  TotalValueLocked,
14
- BorrowIncentivePoolPoints,
15
- ScallopIndexerInstanceParams,
16
- ScallopIndexerParams,
17
- } from '../types';
18
- import { ScallopCache } from './scallopCache';
19
- import { queryKeys } from 'src/constants';
20
-
21
- /**
22
- * @description
23
- * It provides methods to obtain sdk index data from mainnet.
24
- *
25
- *
26
- * @example
27
- * ```typescript
28
- * const scallopIndexer = new scallopIndexer(<parameters>);
29
- * scallopIndexer.<indexer functions>();
30
- * await scallopIndexer.<indexer async functions>();
31
- * ```
32
- */
33
- export class ScallopIndexer {
34
- private readonly cache: ScallopCache;
35
- public readonly params: ScallopIndexerParams;
36
- private readonly _requestClient: AxiosInstance;
37
-
38
- public constructor(
39
- params: ScallopIndexerParams,
40
- instance?: ScallopIndexerInstanceParams
41
- ) {
42
- this.params = params;
43
- this.cache = instance?.cache ?? new ScallopCache(this.params);
44
- this._requestClient = axios.create({
45
- baseURL: params.indexerApiUrl ?? SDK_API_BASE_URL,
46
- headers: {
47
- 'Content-Type': 'application/json',
48
- Accept: 'application/json',
49
- },
50
- timeout: 30000,
51
- });
13
+ } from 'src/types';
14
+ import ScallopAxios, { ScallopAxiosParams } from './scallopAxios';
15
+ import { queryKeys, SDK_API_BASE_URL } from 'src/constants';
16
+
17
+ export type ScallopIndexerParams = {
18
+ indexerApiUrl?: string;
19
+ } & ScallopAxiosParams;
20
+
21
+ class ScallopIndexer extends ScallopAxios {
22
+ constructor(params: ScallopIndexerParams = {}) {
23
+ params.baseUrl = params.indexerApiUrl ?? SDK_API_BASE_URL;
24
+ super(params);
52
25
  }
53
26
 
54
27
  /**
@@ -56,16 +29,11 @@ export class ScallopIndexer {
56
29
  *
57
30
  * @return Market data.
58
31
  */
59
- public async getMarket(): Promise<Pick<Market, 'pools' | 'collaterals'>> {
60
- const response = await this.cache.queryClient.fetchQuery({
61
- queryKey: queryKeys.api.getMarket(),
62
- queryFn: async () => {
63
- return await this._requestClient.get<{
64
- pools: MarketPool[];
65
- collaterals: MarketCollateral[];
66
- }>(`/api/market/migrate`);
67
- },
68
- });
32
+ async getMarket(): Promise<Pick<Market, 'pools' | 'collaterals'>> {
33
+ const response = await this.get<{
34
+ pools: MarketPool[];
35
+ collaterals: MarketCollateral[];
36
+ }>('/api/market/migrate', queryKeys.api.getMarket());
69
37
 
70
38
  if (response.status === 200) {
71
39
  return {
@@ -91,7 +59,7 @@ export class ScallopIndexer {
91
59
  *
92
60
  * @return Market pools data.
93
61
  */
94
- public async getMarketPools(): Promise<Required<MarketPools>> {
62
+ async getMarketPools(): Promise<Required<MarketPools>> {
95
63
  const response = (await this.getMarket()).pools;
96
64
  return response as Required<MarketPools>;
97
65
  }
@@ -101,7 +69,7 @@ export class ScallopIndexer {
101
69
  *
102
70
  * @return Market pool data.
103
71
  */
104
- public async getMarketPool(poolCoinName: string): Promise<MarketPool> {
72
+ async getMarketPool(poolCoinName: string): Promise<MarketPool> {
105
73
  return (await this.getMarketPools())[poolCoinName] as MarketPool;
106
74
  }
107
75
 
@@ -110,7 +78,7 @@ export class ScallopIndexer {
110
78
  *
111
79
  * @return Market collaterals data.
112
80
  */
113
- public async getMarketCollaterals(): Promise<Required<MarketCollaterals>> {
81
+ async getMarketCollaterals(): Promise<Required<MarketCollaterals>> {
114
82
  return (await this.getMarket()).collaterals as Required<MarketCollaterals>;
115
83
  }
116
84
 
@@ -119,7 +87,7 @@ export class ScallopIndexer {
119
87
  *
120
88
  * @return Market collateral data.
121
89
  */
122
- public async getMarketCollateral(
90
+ async getMarketCollateral(
123
91
  collateralCoinName: string
124
92
  ): Promise<MarketCollateral> {
125
93
  return (await this.getMarketCollaterals())[
@@ -132,15 +100,10 @@ export class ScallopIndexer {
132
100
  *
133
101
  * @return Spools data.
134
102
  */
135
- public async getSpools(): Promise<Required<Spools>> {
136
- const response = await this.cache.queryClient.fetchQuery({
137
- queryKey: queryKeys.api.getSpools(),
138
- queryFn: async () => {
139
- return await this._requestClient.get<{
140
- spools: Spool[];
141
- }>(`/api/spools/migrate`);
142
- },
143
- });
103
+ async getSpools(): Promise<Required<Spools>> {
104
+ const response = await this.get<{
105
+ spools: Spool[];
106
+ }>('/api/spools/migrate', queryKeys.api.getSpools());
144
107
 
145
108
  if (response.status === 200) {
146
109
  return response.data.spools.reduce((spools, spool) => {
@@ -157,7 +120,7 @@ export class ScallopIndexer {
157
120
  *
158
121
  * @return Spool data.
159
122
  */
160
- public async getSpool(marketCoinName: string): Promise<Spool> {
123
+ async getSpool(marketCoinName: string): Promise<Spool> {
161
124
  return (await this.getSpools())[marketCoinName] as Spool;
162
125
  }
163
126
 
@@ -166,17 +129,13 @@ export class ScallopIndexer {
166
129
  *
167
130
  * @return Borrow incentive pools data.
168
131
  */
169
- public async getBorrowIncentivePools(): Promise<
170
- Required<BorrowIncentivePools>
171
- > {
172
- const response = await this.cache.queryClient.fetchQuery({
173
- queryKey: queryKeys.api.getBorrowIncentivePool(),
174
- queryFn: async () => {
175
- return await this._requestClient.get<{
176
- borrowIncentivePools: BorrowIncentivePool[];
177
- }>(`/api/borrowIncentivePools/migrate`);
178
- },
179
- });
132
+ async getBorrowIncentivePools(): Promise<Required<BorrowIncentivePools>> {
133
+ const response = await this.get<{
134
+ borrowIncentivePools: BorrowIncentivePool[];
135
+ }>(
136
+ '/api/borrowIncentivePools/migrate',
137
+ queryKeys.api.getBorrowIncentivePool()
138
+ );
180
139
 
181
140
  if (response.status === 200) {
182
141
  return response.data.borrowIncentivePools.reduce(
@@ -208,7 +167,7 @@ export class ScallopIndexer {
208
167
  *
209
168
  * @return Borrow incentive pool data.
210
169
  */
211
- public async getBorrowIncentivePool(
170
+ async getBorrowIncentivePool(
212
171
  borrowIncentiveCoinName: string
213
172
  ): Promise<BorrowIncentivePool> {
214
173
  return (await this.getBorrowIncentivePools())[
@@ -221,25 +180,20 @@ export class ScallopIndexer {
221
180
  *
222
181
  * @return Total value locked.
223
182
  */
224
- public async getTotalValueLocked(): Promise<
183
+ async getTotalValueLocked(): Promise<
225
184
  TotalValueLocked & {
226
185
  totalValueChangeRatio: number;
227
186
  borrowValueChangeRatio: number;
228
187
  supplyValueChangeRatio: number;
229
188
  }
230
189
  > {
231
- const response = await this.cache.queryClient.fetchQuery({
232
- queryKey: queryKeys.api.getTotalValueLocked(),
233
- queryFn: async () => {
234
- return await this._requestClient.get<
235
- TotalValueLocked & {
236
- totalValueChangeRatio: number;
237
- borrowValueChangeRatio: number;
238
- supplyValueChangeRatio: number;
239
- }
240
- >(`/api/market/tvl`);
241
- },
242
- });
190
+ const response = await this.get<
191
+ TotalValueLocked & {
192
+ totalValueChangeRatio: number;
193
+ borrowValueChangeRatio: number;
194
+ supplyValueChangeRatio: number;
195
+ }
196
+ >(`/api/market/tvl`, queryKeys.api.getTotalValueLocked());
243
197
 
244
198
  if (response.status === 200) {
245
199
  return response.data;
@@ -253,11 +207,11 @@ export class ScallopIndexer {
253
207
  *
254
208
  * @return price data.
255
209
  */
256
- public async getCoinPrice(poolCoinName: string): Promise<number> {
210
+ async getCoinPrice(poolCoinName: string): Promise<number> {
257
211
  return (await this.getMarketPool(poolCoinName))?.coinPrice ?? 0;
258
212
  }
259
213
 
260
- public async getCoinPrices(): Promise<Record<string, number>> {
214
+ async getCoinPrices(): Promise<Record<string, number>> {
261
215
  const marketPools = await this.getMarketPools();
262
216
  return Object.entries(marketPools).reduce(
263
217
  (prev, [coinName, market]) => {
@@ -268,3 +222,5 @@ export class ScallopIndexer {
268
222
  );
269
223
  }
270
224
  }
225
+
226
+ export default ScallopIndexer;