@scallop-io/sui-scallop-sdk 2.0.13-merge-split-ve-sca-alpha.5 → 2.1.0

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,102 +1,106 @@
1
- import axios, { AxiosInstance } from 'axios';
1
+ import { PoolAddress, Whitelist } from 'src/types';
2
+ import ScallopAddress, { ScallopAddressParams } from './scallopAddress';
3
+ import { NetworkType, parseStructTag } from '@scallop-io/sui-kit';
4
+ import ScallopAxios from './scallopAxios';
2
5
  import { queryKeys } from 'src/constants';
3
- import {
4
- PoolAddress,
5
- ScallopConstantsInstanceParams,
6
- ScallopConstantsParams,
7
- Whitelist,
8
- } from 'src/types';
9
- import { ScallopCache } from './scallopCache';
10
6
  import { QueryKey } from '@tanstack/query-core';
11
- import { newSuiKit } from './suiKit';
12
- import { ScallopAddress } from './scallopAddress';
13
- import { parseStructTag } from '@scallop-io/sui-kit';
7
+
8
+ const isEmptyObject = (obj: object) => {
9
+ return Object.keys(obj).length === 0;
10
+ };
11
+
12
+ type CoinName = string;
13
+ type CoinType = string;
14
+ type SCoinType = string;
15
+ type OldMarketCoinType = string;
14
16
 
15
17
  /**
16
- * @description
17
- * It provides methods to construct constants for Scallop SDK instances.
18
- *
19
- * @example
20
- * ```typescript
21
- * const scallopConstants = new ScallopConstants();
22
- * await scallopConstants.init();
23
- * ```
18
+ * @description `scallop_sui`, `scallop_usdt`, etc (parsed directly from coin type, ex: `0x...::scallop_sui::SCALLOP_SUI`)
24
19
  */
25
- export class ScallopConstants {
26
- private readonly _requestClient: AxiosInstance;
27
- public address: ScallopAddress;
28
- public cache: ScallopCache;
20
+ type SCoinRawName = string;
29
21
 
22
+ /**
23
+ * @description `ssui`, `susdc`, etc..
24
+ */
25
+ type SCoinName = string;
26
+
27
+ export type ScallopConstantsParams = {
28
+ poolAddressesApiUrl?: string;
29
+ whitelistApiUrl?: string;
30
+ forcePoolAddressInterface?: Record<string, PoolAddress>;
31
+ forceWhitelistInterface?: Whitelist;
32
+ } & ScallopAddressParams;
33
+
34
+ const DEFAULT_WHITELIST = {
35
+ lending: new Set(),
36
+ borrowing: new Set(),
37
+ collateral: new Set(),
38
+ packages: new Set(),
39
+ scoin: new Set(),
40
+ spool: new Set(),
41
+ borrowIncentiveRewards: new Set(),
42
+ rewardsAsPoint: new Set(),
43
+ suiBridge: new Set(),
44
+ wormhole: new Set(),
45
+ oracles: new Set(),
46
+ pythEndpoints: new Set(),
47
+ deprecated: new Set(),
48
+ emerging: new Set(),
49
+ } as Whitelist;
50
+
51
+ class ScallopConstants extends ScallopAddress {
30
52
  private _poolAddresses: Record<string, PoolAddress | undefined> = {};
31
- private _whitelist: Whitelist = {
32
- lending: new Set(),
33
- borrowing: new Set(),
34
- collateral: new Set(),
35
- packages: new Set(),
36
- scoin: new Set(),
37
- spool: new Set(),
38
- borrowIncentiveRewards: new Set(),
39
- rewardsAsPoint: new Set(),
40
- suiBridge: new Set(),
41
- wormhole: new Set(),
42
- oracles: new Set(),
43
- pythEndpoints: new Set(),
44
- deprecated: new Set(),
45
- emerging: new Set(),
46
- };
47
-
48
- private _coinDecimals: Record<string, number | undefined> = {};
49
- private _coinNameToOldMarketCoinTypeMap: Record<string, string | undefined> =
50
- {};
51
- private _scoinRawNameToSCoinNameMap: Record<string, string | undefined> = {};
52
- private _scoinTypeToSCoinNameMap: Record<string, string | undefined> = {};
53
- private _wormholeCoinTypeToCoinNameMap: Record<string, string | undefined> =
54
- {};
55
- private _voloCoinTypeToCoinNameMap: Record<string, string | undefined> = {};
56
- private _suiBridgeCoinTypeToCoinNameMap: Record<string, string | undefined> =
53
+ private _whitelist: Whitelist = DEFAULT_WHITELIST;
54
+
55
+ /**
56
+ * @description coin names to coin decimal map
57
+ */
58
+ public coinDecimals: Record<CoinName, number | undefined> = {};
59
+ public coinNameToOldMarketCoinTypeMap: Record<
60
+ CoinName,
61
+ OldMarketCoinType | undefined
62
+ > = {};
63
+ public scoinRawNameToSCoinNameMap: Record<
64
+ SCoinRawName,
65
+ SCoinName | undefined
66
+ > = {};
67
+ public scoinTypeToSCoinNameMap: Record<SCoinType, SCoinName | undefined> = {};
68
+ public wormholeCoinTypeToCoinNameMap: Record<CoinType, CoinName | undefined> =
57
69
  {};
58
- private _coinTypes: Record<string, string | undefined> = {};
59
- private _sCoinTypes: Record<string, string | undefined> = {};
60
- private _coinTypeToCoinNameMap: Record<string, string | undefined> = {};
61
- private _supportedBorrowIncentiveRewards: Set<string> = new Set();
62
-
63
- constructor(
64
- public readonly params: ScallopConstantsParams,
65
- instance?: ScallopConstantsInstanceParams
66
- ) {
67
- this.params = params;
68
- this._requestClient = axios.create({
69
- headers: {
70
- 'Content-Type': 'application/json',
71
- Accept: 'application/json',
72
- },
73
- timeout: 8000,
74
- });
70
+ public voloCoinTypeToCoinNameMap: Record<CoinType, CoinName | undefined> = {};
71
+ public suiBridgeCoinTypeToCoinNameMap: Record<
72
+ CoinType,
73
+ CoinName | undefined
74
+ > = {};
75
75
 
76
- this.cache =
77
- instance?.address?.cache ??
78
- instance?.cache ??
79
- new ScallopCache(this.params, {
80
- suiKit: newSuiKit(this.params),
81
- });
82
-
83
- this.address =
84
- instance?.address ??
85
- new ScallopAddress(this.params, {
86
- cache: this.cache,
87
- });
88
-
89
- if (params.forcePoolAddressInterface) {
90
- this._poolAddresses = params.forcePoolAddressInterface;
91
- }
76
+ /**
77
+ * @description coin names to coin types map
78
+ */
79
+ public coinTypes: Record<CoinName, CoinType | undefined> = {};
92
80
 
93
- if (params.forceWhitelistInterface) {
94
- this._whitelist = params.forceWhitelistInterface;
95
- }
81
+ /**
82
+ * @description scoin names to scoin types map
83
+ */
84
+ public sCoinTypes: Record<SCoinName, SCoinType | undefined> = {};
85
+ public coinTypeToCoinNameMap: Record<CoinType, CoinName | undefined> = {};
86
+
87
+ /**
88
+ * @description Supported borrow incentive reward coin names
89
+ */
90
+ public supportedBorrowIncentiveRewards: Set<CoinName> = new Set();
91
+
92
+ private scallopConstantAxios: ScallopAxios;
93
+
94
+ constructor(public readonly params: ScallopConstantsParams = {}) {
95
+ super(params);
96
+ this.scallopConstantAxios = new ScallopAxios();
96
97
  }
97
98
 
98
- get isAddressInitialized() {
99
- return !this.isEmptyObject(this.address.getAllAddresses());
99
+ get protocolObjectId() {
100
+ return (
101
+ (this.get('core.object') as string | undefined) ??
102
+ ('0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf' as const)
103
+ );
100
104
  }
101
105
 
102
106
  get isInitialized() {
@@ -112,210 +116,193 @@ export class ScallopConstants {
112
116
  'emerging',
113
117
  ] as const;
114
118
  return (
115
- this.isAddressInitialized && // address is initialized
116
- !this.isEmptyObject(this._poolAddresses) && // poolAddresses is initialized
117
- REQUIRED_WHITELIST_KEYS.every(
118
- (t) => this.whitelist[t] && this.whitelist[t].size > 0
119
- ) // whitelist is initialized
119
+ this.isAddressInitialized() && // address is initialized
120
+ !isEmptyObject(this.poolAddresses) && // poolAddresses is initialized
121
+ REQUIRED_WHITELIST_KEYS.every((t) => this.whitelist[t].size > 0) // whitelist is initialized
120
122
  );
121
123
  }
122
124
 
123
- get queryClient() {
124
- return this.cache.queryClient;
125
+ get whitelist() {
126
+ return new Proxy(this._whitelist, {
127
+ get: (target, key: keyof Whitelist) => {
128
+ return target[key] ?? DEFAULT_WHITELIST[key];
129
+ },
130
+ });
125
131
  }
126
132
 
127
133
  get poolAddresses() {
128
- return this._poolAddresses;
134
+ return new Proxy(this._poolAddresses, {
135
+ get: (target, key: string) => {
136
+ return target[key] ?? undefined;
137
+ },
138
+ });
129
139
  }
130
140
 
131
- get whitelist() {
132
- return this._whitelist;
141
+ private isAddressInitialized({
142
+ networkType = 'mainnet',
143
+ }: {
144
+ networkType?: NetworkType;
145
+ } = {}) {
146
+ const addresses = this.getAddresses(networkType);
147
+ return !addresses || isEmptyObject(addresses);
133
148
  }
134
149
 
135
150
  parseToOldMarketCoin(coinType: string) {
136
151
  return `${this.protocolObjectId}::reserve::MarketCoin<${coinType}>`;
137
152
  }
138
153
 
139
- get protocolObjectId() {
140
- return (
141
- (this.address.get('core.object') as string | undefined) ??
142
- ('0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf' as const)
143
- );
144
- }
154
+ async init({
155
+ networkType = 'mainnet',
156
+ force = false,
157
+ addressId,
158
+ constantsParams = this.params,
159
+ }: {
160
+ networkType?: NetworkType;
161
+ force?: boolean;
162
+ addressId?: string;
163
+ constantsParams?: Partial<ScallopConstantsParams>;
164
+ } = {}) {
165
+ // check if scallop address is initialized
166
+ const addresses = this.getAddresses(networkType);
167
+ if (!addresses || Object.keys(addresses).length === 0 || force) {
168
+ await this.read(addressId); // ScallopAddress read()
169
+ }
145
170
 
146
- /**
147
- * @description
148
- * Return maps of coin names to coin decimals.
149
- */
150
- get coinDecimals() {
151
- if (this.isEmptyObject(this._coinDecimals)) {
152
- this._coinDecimals = Object.fromEntries([
153
- ...Object.entries(this.poolAddresses)
154
- .filter(([_, value]) => !!value)
155
- .map(([key, value]) => [key, value!.decimals]),
156
- ...Object.entries(this.poolAddresses)
157
- .filter(([_, value]) => !!value?.sCoinName)
158
- .map(([_, value]) => [value!.sCoinName, value!.decimals]),
159
- ]);
171
+ // Initialization function
172
+ if (constantsParams.forcePoolAddressInterface) {
173
+ this._poolAddresses = constantsParams.forcePoolAddressInterface;
160
174
  }
161
- return this._coinDecimals;
162
- }
163
175
 
164
- /**
165
- * @description
166
- * Return maps of coin names to coin types.
167
- */
168
- get coinTypes() {
169
- if (this.isEmptyObject(this._coinTypes))
170
- this._coinTypes = Object.fromEntries([
171
- ...Object.entries(this.poolAddresses)
172
- .filter(([_, value]) => !!value)
173
- .map(([key, value]) => [key, value?.coinType]),
174
- ...Object.entries(this.poolAddresses)
175
- .filter(([_, value]) => !!value && value.sCoinName && value.sCoinType)
176
- .map(([_, value]) => [value!.sCoinName, value!.sCoinType]),
177
- ]);
178
- return this._coinTypes;
179
- }
176
+ if (constantsParams.forceWhitelistInterface) {
177
+ this._whitelist = constantsParams.forceWhitelistInterface;
178
+ }
180
179
 
181
- /**
182
- * @description
183
- * Return maps of coin types to its coin name
184
- */
185
- get coinTypeToCoinNameMap() {
186
- if (this.isEmptyObject(this._coinTypeToCoinNameMap))
187
- this._coinTypeToCoinNameMap = Object.fromEntries(
188
- Object.entries(this.coinTypes).map(([key, val]) => [val, key])
189
- );
190
- return this._coinTypeToCoinNameMap;
191
- }
180
+ if (this.isInitialized && !force) {
181
+ return;
182
+ }
192
183
 
193
- /**
194
- * @description
195
- * Return maps of wormhole coin types to its coin name.
196
- */
197
- get wormholeCoinTypeToCoinName() {
198
- if (this.isEmptyObject(this._wormholeCoinTypeToCoinNameMap))
199
- this._wormholeCoinTypeToCoinNameMap = Object.fromEntries(
200
- Object.entries(this.poolAddresses)
201
- .filter(([key, value]) => !!value && this.whitelist.wormhole.has(key))
202
- .map(([_, value]) => [value!.coinType, value!.coinName])
203
- );
204
- return this._wormholeCoinTypeToCoinNameMap;
205
- }
184
+ const [whitelistResponse, poolAddressesResponse] = await Promise.all([
185
+ this.readWhiteList(),
186
+ this.readPoolAddresses(),
187
+ ]);
206
188
 
207
- /**
208
- * @description
209
- * Return maps of coin name to its old market coin type (...::reserve::MarketCoin<coinType>)
210
- */
211
- get coinNameToOldMarketCoinTypeMap() {
212
- if (this.isEmptyObject(this._coinNameToOldMarketCoinTypeMap))
213
- this._coinNameToOldMarketCoinTypeMap = Object.fromEntries(
214
- Object.entries(this.poolAddresses)
215
- .filter(([_, value]) => !!value)
216
- .map(([_, value]) => [
217
- value!.coinName,
218
- this.parseToOldMarketCoin(value!.coinType),
219
- ])
189
+ if (!this.params.forceWhitelistInterface) {
190
+ this._whitelist = Object.keys(this._whitelist).reduce(
191
+ (acc, key: unknown) => {
192
+ const whiteListKey = key as keyof Whitelist;
193
+ const whiteListValue = whitelistResponse[whiteListKey];
194
+ acc[whiteListKey] =
195
+ whiteListValue instanceof Set
196
+ ? whiteListValue
197
+ : Array.isArray(whiteListValue)
198
+ ? new Set(whiteListValue)
199
+ : new Set();
200
+ return acc;
201
+ },
202
+ {} as Whitelist
220
203
  );
221
- return this._coinNameToOldMarketCoinTypeMap;
222
- }
204
+ }
223
205
 
224
- /**
225
- * @description
226
- * Return maps of sCoin raw name from its type to its sCoin name. (e.g. 'scallop_sui' -> 'ssui')
227
- */
228
- get sCoinRawNameToScoinNameMap() {
229
- if (this.isEmptyObject(this._scoinRawNameToSCoinNameMap))
230
- this._scoinRawNameToSCoinNameMap = Object.fromEntries(
231
- Object.entries(this.poolAddresses)
232
- .filter(([_, value]) => !!value && value.sCoinType && value.sCoinName)
233
- .map(([_, value]) => {
234
- const scoinRawName = parseStructTag(value!.sCoinType!).name;
235
- return [scoinRawName, value!.sCoinName!];
206
+ if (!this.params.forcePoolAddressInterface) {
207
+ this._poolAddresses = Object.fromEntries(
208
+ Object.entries(poolAddressesResponse)
209
+ .filter(([key]) =>
210
+ Object.values(this._whitelist).some((set) => set.has(key))
211
+ )
212
+ .map(([key, value]) => {
213
+ const parsedValue = Object.fromEntries(
214
+ Object.entries(value).map(([k, v]) => [
215
+ k,
216
+ typeof v === 'boolean' ? (v ?? false) : v || undefined,
217
+ ])
218
+ );
219
+ return [key, parsedValue as PoolAddress];
236
220
  })
237
221
  );
238
-
239
- return this._scoinRawNameToSCoinNameMap;
222
+ }
223
+ this.initConstants();
240
224
  }
241
225
 
242
- /**
243
- * @description
244
- * Return maps of scoin type to its sCoin name
245
- */
246
- get sCoinTypeToSCoinNameMap() {
247
- if (this.isEmptyObject(this._scoinTypeToSCoinNameMap))
248
- this._scoinTypeToSCoinNameMap = Object.fromEntries(
249
- Object.entries(this.poolAddresses)
250
- .filter(([_, value]) => !!value && value.sCoinType && value.sCoinName)
251
- .map(([_, value]) => [value!.sCoinType!, value!.sCoinName!])
252
- );
226
+ private initConstants() {
227
+ this.coinDecimals = Object.fromEntries([
228
+ ...Object.entries(this.poolAddresses)
229
+ .filter(([_, value]) => !!value)
230
+ .map(([key, value]) => [key, value!.decimals]),
231
+ ...Object.entries(this.poolAddresses)
232
+ .filter(([_, value]) => !!value?.sCoinName)
233
+ .map(([_, value]) => [value!.sCoinName, value!.decimals]),
234
+ ]);
253
235
 
254
- return this._scoinTypeToSCoinNameMap;
255
- }
236
+ this.coinTypes = Object.fromEntries([
237
+ ...Object.entries(this.poolAddresses)
238
+ .filter(([_, value]) => !!value)
239
+ .map(([key, value]) => [key, value?.coinType]),
240
+ ...Object.entries(this.poolAddresses)
241
+ .filter(([_, value]) => !!value && value.sCoinName && value.sCoinType)
242
+ .map(([_, value]) => [value!.sCoinName, value!.sCoinType]),
243
+ ]);
256
244
 
257
- /**
258
- * @description
259
- * Return maps of volo coin type to its coin name
260
- */
261
- get voloCoinTypeToCoinNameMap() {
262
- if (this.isEmptyObject(this._voloCoinTypeToCoinNameMap))
263
- this._voloCoinTypeToCoinNameMap = {
264
- [this.poolAddresses['vsui']!.coinType]: 'vsui',
265
- };
266
- return this._voloCoinTypeToCoinNameMap;
267
- }
245
+ this.coinTypeToCoinNameMap = Object.fromEntries(
246
+ Object.entries(this.coinTypes).map(([key, val]) => [val, key])
247
+ );
268
248
 
269
- /**
270
- * @description
271
- * Return maps of sui bridge coin type to its coin name
272
- */
273
- get suiBridgeCoinTypeToCoinNameMap() {
274
- if (this.isEmptyObject(this._suiBridgeCoinTypeToCoinNameMap))
275
- this._suiBridgeCoinTypeToCoinNameMap = Object.fromEntries(
276
- Object.entries(this.poolAddresses)
277
- .filter(
278
- ([_, value]) =>
279
- !!value && this.whitelist.suiBridge.has(value.coinName)
280
- )
281
- .map(([_, value]) => [value!.coinType, value!.coinName])
282
- );
283
- return this._suiBridgeCoinTypeToCoinNameMap;
284
- }
249
+ this.wormholeCoinTypeToCoinNameMap = Object.fromEntries(
250
+ Object.entries(this.poolAddresses)
251
+ .filter(([key, value]) => !!value && this.whitelist.wormhole.has(key))
252
+ .map(([_, value]) => [value!.coinType, value!.coinName])
253
+ );
285
254
 
286
- /**
287
- * @description
288
- * Return maps of sCoin coin name to its coin type
289
- */
290
- get sCoinTypes() {
291
- if (this.isEmptyObject(this._sCoinTypes))
292
- this._sCoinTypes = Object.fromEntries(
293
- Object.entries(this.poolAddresses)
294
- .filter(([_, value]) => !!value && value.sCoinName && value.sCoinType)
295
- .map(([_, value]) => [value!.sCoinName, value!.sCoinType!])
296
- );
255
+ this.coinNameToOldMarketCoinTypeMap = Object.fromEntries(
256
+ Object.entries(this.poolAddresses)
257
+ .filter(([_, value]) => !!value)
258
+ .map(([_, value]) => [
259
+ value!.coinName,
260
+ this.parseToOldMarketCoin(value!.coinType),
261
+ ])
262
+ );
297
263
 
298
- return this._sCoinTypes;
299
- }
264
+ this.scoinRawNameToSCoinNameMap = Object.fromEntries(
265
+ Object.entries(this.poolAddresses)
266
+ .filter(([_, value]) => !!value && value.sCoinType && value.sCoinName)
267
+ .map(([_, value]) => {
268
+ const scoinRawName = parseStructTag(value!.sCoinType!).name;
269
+ return [scoinRawName, value!.sCoinName!];
270
+ })
271
+ );
300
272
 
301
- /**
302
- * @description
303
- * Return set of supported coin types for borrow incentive rewards
304
- * (all supported pools + sCoins + custom coins from `whitelist.borrowIncentiveRewards`)
305
- */
306
- get supportedBorrowIncentiveRewards() {
307
- if (!this._supportedBorrowIncentiveRewards.size)
308
- this._supportedBorrowIncentiveRewards = new Set([
309
- ...Object.values(this.poolAddresses)
310
- .filter((t) => !!t)
311
- .map((t) => (t.sCoinName ? [t.coinName, t.sCoinName] : [t.coinName]))
312
- .flat(),
313
- ]);
314
- return this._supportedBorrowIncentiveRewards;
315
- }
273
+ this.scoinTypeToSCoinNameMap = Object.fromEntries(
274
+ Object.entries(this.poolAddresses)
275
+ .filter(([_, value]) => !!value && value.sCoinType && value.sCoinName)
276
+ .map(([_, value]) => [value!.sCoinType!, value!.sCoinName!])
277
+ );
278
+
279
+ const vSuiCoinType = this.poolAddresses['vsui']?.coinType;
280
+ if (vSuiCoinType)
281
+ this.voloCoinTypeToCoinNameMap = {
282
+ [vSuiCoinType]: 'vsui',
283
+ };
316
284
 
317
- private isEmptyObject(obj: Record<string, unknown>) {
318
- return Object.keys(obj).length === 0;
285
+ this.suiBridgeCoinTypeToCoinNameMap = Object.fromEntries(
286
+ Object.entries(this.poolAddresses)
287
+ .filter(
288
+ ([_, value]) =>
289
+ !!value && this.whitelist.suiBridge.has(value.coinName)
290
+ )
291
+ .map(([_, value]) => [value!.coinType, value!.coinName])
292
+ );
293
+
294
+ this.sCoinTypes = Object.fromEntries(
295
+ Object.entries(this.poolAddresses)
296
+ .filter(([_, value]) => !!value && value.sCoinName && value.sCoinType)
297
+ .map(([_, value]) => [value!.sCoinName, value!.sCoinType!])
298
+ );
299
+
300
+ this.supportedBorrowIncentiveRewards = new Set([
301
+ ...Object.values(this.poolAddresses)
302
+ .filter((t) => !!t)
303
+ .map((t) => (t.sCoinName ? [t.coinName, t.sCoinName] : [t.coinName]))
304
+ .flat(),
305
+ ]);
319
306
  }
320
307
 
321
308
  private async readApi<T>({
@@ -325,15 +312,7 @@ export class ScallopConstants {
325
312
  url: string;
326
313
  queryKey: QueryKey;
327
314
  }) {
328
- const resp = await this.queryClient.fetchQuery({
329
- queryKey,
330
- queryFn: async () => {
331
- return await this._requestClient.get(url, {
332
- timeout: 4000,
333
- });
334
- },
335
- });
336
-
315
+ const resp = await this.scallopConstantAxios.get<T>(url, queryKey);
337
316
  if (resp.status === 200) {
338
317
  return resp.data as T;
339
318
  } else {
@@ -366,60 +345,6 @@ export class ScallopConstants {
366
345
  queryKey: queryKeys.api.getPoolAddresses(),
367
346
  });
368
347
  }
369
-
370
- async init(params?: Partial<ScallopConstantsParams>) {
371
- if (!this.isAddressInitialized) {
372
- await this.address.read();
373
- }
374
-
375
- if (params?.forcePoolAddressInterface) {
376
- this._poolAddresses = params?.forcePoolAddressInterface;
377
- }
378
-
379
- if (params?.forceWhitelistInterface) {
380
- this._whitelist = params?.forceWhitelistInterface;
381
- }
382
-
383
- if (this.isInitialized) return;
384
-
385
- const [whitelistResponse, poolAddressesResponse] = await Promise.all([
386
- this.readWhiteList(),
387
- this.readPoolAddresses(),
388
- ]);
389
-
390
- if (!this.params.forceWhitelistInterface) {
391
- this._whitelist = Object.keys(this._whitelist).reduce(
392
- (acc, key: unknown) => {
393
- const whiteListKey = key as keyof Whitelist;
394
- const whiteListValue = whitelistResponse[whiteListKey];
395
- acc[whiteListKey] =
396
- whiteListValue instanceof Set
397
- ? whiteListValue
398
- : Array.isArray(whiteListValue)
399
- ? new Set(whiteListValue)
400
- : new Set();
401
- return acc;
402
- },
403
- {} as Whitelist
404
- );
405
- }
406
-
407
- if (!this.params.forcePoolAddressInterface) {
408
- this._poolAddresses = Object.fromEntries(
409
- Object.entries(poolAddressesResponse)
410
- .filter(([key]) =>
411
- Object.values(this.whitelist).some((set) => set.has(key))
412
- )
413
- .map(([key, value]) => {
414
- const parsedValue = Object.fromEntries(
415
- Object.entries(value).map(([k, v]) => [
416
- k,
417
- typeof v === 'boolean' ? (v ?? false) : v || undefined,
418
- ])
419
- );
420
- return [key, parsedValue as PoolAddress];
421
- })
422
- );
423
- }
424
- }
425
348
  }
349
+
350
+ export default ScallopConstants;