@scallop-io/sui-scallop-sdk 2.0.13-merge-split-ve-sca-alpha.4 → 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.
- package/dist/index.d.mts +622 -697
- package/dist/index.d.ts +622 -697
- package/dist/index.js +32 -33
- package/dist/index.mjs +10 -10
- package/package.json +8 -18
- package/src/builders/borrowIncentiveBuilder.ts +8 -18
- package/src/builders/coreBuilder.ts +2 -2
- package/src/builders/index.ts +2 -2
- package/src/builders/oracles/index.ts +2 -3
- package/src/builders/oracles/pyth.ts +2 -2
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +14 -132
- package/src/constants/queryKeys.ts +29 -54
- package/src/constants/testAddress.ts +6 -12
- package/src/index.ts +11 -1
- package/src/models/index.ts +11 -9
- package/src/models/interface.ts +36 -0
- package/src/models/scallop.ts +38 -133
- package/src/models/scallopAddress.ts +127 -142
- package/src/models/scallopAxios.ts +185 -0
- package/src/models/scallopBuilder.ts +45 -75
- package/src/models/scallopClient.ts +124 -154
- package/src/models/scallopConstants.ts +248 -323
- package/src/models/scallopIndexer.ts +54 -98
- package/src/models/scallopQuery.ts +145 -190
- package/src/models/scallopQueryClient.ts +29 -0
- package/src/models/scallopSuiKit.ts +432 -0
- package/src/models/scallopUtils.ts +260 -164
- package/src/queries/borrowIncentiveQuery.ts +28 -16
- package/src/queries/borrowLimitQuery.ts +1 -1
- package/src/queries/coreQuery.ts +148 -107
- package/src/queries/flashloanFeeQuery.ts +12 -6
- package/src/queries/index.ts +0 -1
- package/src/queries/isolatedAssetQuery.ts +3 -3
- package/src/queries/loyaltyProgramQuery.ts +10 -8
- package/src/queries/ownerQuery.ts +32 -0
- package/src/queries/portfolioQuery.ts +4 -5
- package/src/queries/priceQuery.ts +14 -8
- package/src/queries/referralQuery.ts +9 -3
- package/src/queries/sCoinQuery.ts +4 -4
- package/src/queries/spoolQuery.ts +11 -11
- package/src/queries/supplyLimitQuery.ts +1 -1
- package/src/queries/switchboardQuery.ts +1 -1
- package/src/queries/vescaQuery.ts +31 -27
- package/src/queries/xOracleQuery.ts +13 -8
- package/src/types/address.ts +0 -3
- package/src/types/builder/core.ts +1 -1
- package/src/types/builder/vesca.ts +10 -20
- package/src/types/constant/queryKeys.ts +48 -0
- package/src/types/index.ts +0 -1
- package/src/utils/builder.ts +1 -1
- package/src/utils/util.ts +1 -33
- package/src/models/scallopCache.ts +0 -428
- package/src/queries/objectsQuery.ts +0 -18
- package/src/types/model.ts +0 -117
|
@@ -1,54 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
BorrowIncentivePool,
|
|
3
|
+
BorrowIncentivePoolPoints,
|
|
4
|
+
BorrowIncentivePools,
|
|
4
5
|
Market,
|
|
5
|
-
MarketPools,
|
|
6
|
-
MarketPool,
|
|
7
|
-
MarketCollaterals,
|
|
8
6
|
MarketCollateral,
|
|
9
|
-
|
|
7
|
+
MarketCollaterals,
|
|
8
|
+
MarketPool,
|
|
9
|
+
MarketPools,
|
|
10
10
|
Spool,
|
|
11
|
-
|
|
12
|
-
BorrowIncentivePool,
|
|
11
|
+
Spools,
|
|
13
12
|
TotalValueLocked,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
60
|
-
const response = await this.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
136
|
-
const response = await this.
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
210
|
+
async getCoinPrice(poolCoinName: string): Promise<number> {
|
|
257
211
|
return (await this.getMarketPool(poolCoinName))?.coinPrice ?? 0;
|
|
258
212
|
}
|
|
259
213
|
|
|
260
|
-
|
|
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;
|