@scallop-io/sui-scallop-sdk 2.0.0-alpha.2 → 2.0.0-alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -44,7 +44,6 @@ export class ScallopConstants {
44
44
  };
45
45
 
46
46
  private _coinDecimals: Record<string, number | undefined> = {};
47
- private _coinNameToCoinTypeMap: Record<string, string | undefined> = {};
48
47
  private _coinNameToOldMarketCoinTypeMap: Record<string, string | undefined> =
49
48
  {};
50
49
  private _scoinRawNameToSCoinNameMap: Record<string, string | undefined> = {};
@@ -99,7 +98,9 @@ export class ScallopConstants {
99
98
 
100
99
  get isInitialized() {
101
100
  return (
102
- !!this._poolAddresses && !!this._whitelist && this.isAddressInitialized
101
+ !this.isEmptyObject(this._poolAddresses) &&
102
+ Object.values(this._whitelist).every((t) => t.size > 0) &&
103
+ this.isAddressInitialized
103
104
  );
104
105
  }
105
106
 
@@ -163,23 +164,10 @@ export class ScallopConstants {
163
164
  return this._wormholeCoinTypeToCoinNameMap;
164
165
  }
165
166
 
166
- get coinNameToCoinTypeMap() {
167
- if (this.isEmptyObject(this._coinNameToCoinTypeMap))
168
- this._coinNameToCoinTypeMap = Object.fromEntries(
169
- Object.entries(this.poolAddresses)
170
- .filter(([_, value]) => !!value)
171
- .map(([_, value]) => [value!.coinName, value!.coinType])
172
- );
173
- return this._coinNameToCoinTypeMap;
174
- }
175
-
176
167
  get coinTypeToCoinNameMap() {
177
168
  if (this.isEmptyObject(this._coinTypeToCoinNameMap))
178
169
  this._coinTypeToCoinNameMap = Object.fromEntries(
179
- Object.entries(this.coinNameToCoinTypeMap).map(([key, val]) => [
180
- val,
181
- key,
182
- ])
170
+ Object.entries(this.coinTypes).map(([key, val]) => [val, key])
183
171
  );
184
172
  return this._coinTypeToCoinNameMap;
185
173
  }
@@ -292,7 +280,8 @@ export class ScallopConstants {
292
280
  async readWhiteList() {
293
281
  const response = await this.readApi<Record<keyof Whitelist, string[]>>({
294
282
  url:
295
- this.params.whitelistApiUrl ?? 'https://sui.apis.scallop.io/whitelist',
283
+ this.params.whitelistApiUrl ??
284
+ `https://sui.apis.scallop.io/pool/whitelist/${this.params.whitelistId}`,
296
285
  queryKey: queryKeys.api.getWhiteList(),
297
286
  });
298
287
 
@@ -305,7 +294,7 @@ export class ScallopConstants {
305
294
  return await this.readApi<Record<string, PoolAddress>>({
306
295
  url:
307
296
  this.params.poolAddressesApiUrl ??
308
- `https://sui.apis.scallop.io/poolAddresses`,
297
+ `https://sui.apis.scallop.io/pool/addresses`,
309
298
  queryKey: queryKeys.api.getPoolAddresses(),
310
299
  });
311
300
  }
@@ -323,20 +312,42 @@ export class ScallopConstants {
323
312
  this._whitelist = params?.forceWhitelistInterface;
324
313
  }
325
314
 
315
+ console.log({
316
+ isAddressInitialized: this.isAddressInitialized,
317
+ a: params?.forcePoolAddressInterface,
318
+ b: params?.forceWhitelistInterface,
319
+ isInitialized: this.isInitialized,
320
+ });
326
321
  if (this.isInitialized) return;
327
322
 
328
323
  const [whitelistResponse, poolAddressesResponse] = await Promise.all([
329
324
  this.readWhiteList(),
330
325
  this.readPoolAddresses(),
331
326
  ]);
327
+
332
328
  if (!this.params.forceWhitelistInterface) {
333
- this._whitelist = whitelistResponse;
329
+ this._whitelist = Object.fromEntries(
330
+ Object.entries(whitelistResponse)
331
+ .filter(([key]) => key !== 'id')
332
+ .map(([key, value]) => [
333
+ key as keyof Whitelist,
334
+ key !== 'id' ? new Set(value) : value,
335
+ ])
336
+ ) as Whitelist;
334
337
  }
335
338
  if (!this.params.forcePoolAddressInterface)
336
339
  this._poolAddresses = Object.fromEntries(
337
- Object.entries(poolAddressesResponse).filter(([key]) =>
338
- Object.values(this.whitelist).some((set) => set.has(key))
339
- )
340
+ Object.entries(poolAddressesResponse)
341
+ .filter(([key]) =>
342
+ Object.values(this.whitelist).some((set) => set.has(key))
343
+ )
344
+ .map(([key, value]) => {
345
+ const parsedValue = Object.fromEntries(
346
+ Object.entries(value).map(([k, v]) => [k, v || undefined])
347
+ );
348
+ return [key, parsedValue as PoolAddress];
349
+ })
340
350
  );
351
+ console.log({ p: this._poolAddresses });
341
352
  }
342
353
  }
@@ -146,7 +146,7 @@ export class ScallopUtils {
146
146
  if (useOldMarketCoin) {
147
147
  return this.constants.coinNameToOldMarketCoinTypeMap[coinName] ?? '';
148
148
  }
149
- return this.constants.coinNameToCoinTypeMap[coinName] ?? '';
149
+ return this.constants.coinTypes[coinName] ?? '';
150
150
  }
151
151
 
152
152
  /**
@@ -174,8 +174,10 @@ export const queryBorrowIncentiveAccounts = async (
174
174
  const borrowIncentiveAccounts: BorrowIncentiveAccounts = Object.values(
175
175
  borrowIncentiveAccountsQueryData?.pool_records ?? []
176
176
  ).reduce((accounts, accountData) => {
177
- const parsedBorrowIncentiveAccount =
178
- parseOriginBorrowIncentiveAccountData(accountData);
177
+ const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(
178
+ utils,
179
+ accountData
180
+ );
179
181
  const poolType = parsedBorrowIncentiveAccount.poolType;
180
182
  const coinName = utils.parseCoinNameFromType(poolType);
181
183
 
@@ -188,7 +188,10 @@ export const getPoolAddresses = async (
188
188
  const { symbol, metaData: coinMetadataId } =
189
189
  addressApiResponse.core.coins[coinName];
190
190
 
191
- let spoolData = undefined;
191
+ let spoolData = {
192
+ spool: '',
193
+ spoolReward: '',
194
+ };
192
195
  const _spoolData = addressApiResponse.spool.pools[`s${coinName}`];
193
196
  // @ts-ignore
194
197
  if (_spoolData) {
@@ -197,11 +200,15 @@ export const getPoolAddresses = async (
197
200
  spoolData = {
198
201
  spool,
199
202
  spoolReward,
200
- coinMetadataId,
201
203
  };
202
204
  }
203
205
 
204
- let sCoinData = undefined;
206
+ let sCoinData = {
207
+ sCoinType: '',
208
+ sCoinTreasury: '',
209
+ sCoinMetadataId: '',
210
+ sCoinSymbol: '',
211
+ };
205
212
  const sCoinName = `s${coinName}`;
206
213
  const _sCoinData = addressApiResponse.scoin.coins[sCoinName];
207
214
  if (_sCoinData) {
@@ -219,7 +226,21 @@ export const getPoolAddresses = async (
219
226
  };
220
227
  }
221
228
 
222
- const { feed: pythFeed, feedObject: pythFeedObjectId } =
229
+ let pythData = {
230
+ pythFeed: '',
231
+ pythFeedObjectId: '',
232
+ };
233
+
234
+ if (addressApiResponse.core.coins[coinName]?.oracle.pyth) {
235
+ const { feed: pythFeed, feedObject: pythFeedObjectId } =
236
+ //@ts-ignore
237
+ addressApiResponse.core.coins[coinName].oracle.pyth;
238
+ pythData = {
239
+ pythFeed,
240
+ pythFeedObjectId,
241
+ };
242
+ }
243
+ const { feed: _pythFeed, feedObject: _pythFeedObjectId } =
223
244
  //@ts-ignore
224
245
  addressApiResponse.core.coins[coinName].oracle.pyth;
225
246
 
@@ -243,18 +264,17 @@ export const getPoolAddresses = async (
243
264
  interestModel: addresses[3] ?? '',
244
265
  riskModel: addresses[4],
245
266
  borrowFeeKey: addresses[5] ?? '',
246
- supplyLimitKey: addresses[6],
247
- borrowLimitKey: addresses[7],
248
- isolatedAssetKey: addresses[8],
249
- ...(spoolData ?? {}),
250
- ...(sCoinData ?? {}),
267
+ supplyLimitKey: addresses[6] ?? '',
268
+ borrowLimitKey: addresses[7] ?? '',
269
+ isolatedAssetKey: addresses[8] ?? '',
270
+ ...spoolData,
271
+ ...sCoinData,
251
272
  sCoinName,
252
273
  coinMetadataId,
253
274
  coinType,
254
275
  spoolName,
255
276
  decimals,
256
- pythFeed,
257
- pythFeedObjectId,
277
+ ...pythData,
258
278
  flashloanFeeObject: flashloanFeeObjectIds[coinType] ?? '',
259
279
  };
260
280
 
@@ -549,7 +549,6 @@ export const getObligationAccount = async (
549
549
  borrowIncentivePool.points[
550
550
  query.utils.parseSCoinTypeNameToMarketCoinName(key)
551
551
  ];
552
-
553
552
  if (accountPoint && poolPoint) {
554
553
  let availableClaimAmount = BigNumber(0);
555
554
  let availableClaimCoin = BigNumber(0);
@@ -84,6 +84,7 @@ export type ScallopIndexerParams = ScallopCacheParams & {
84
84
  export type ScallopAddressParams = ScallopCacheParams & {
85
85
  addressApiUrl?: string;
86
86
  addressId: string;
87
+ whitelistId: string;
87
88
  auth?: string;
88
89
  network?: NetworkType;
89
90
  forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { normalizeStructTag, parseStructTag } from '@mysten/sui/utils';
2
+ import { normalizeStructTag } from '@mysten/sui/utils';
3
3
  import type { ScallopUtils } from '../models';
4
4
  import type {
5
5
  OriginMarketPoolData,
@@ -581,6 +581,7 @@ export const parseOriginBorrowIncentiveAccountPoolPointData = (
581
581
  * @return Parsed borrow incentive account data
582
582
  */
583
583
  export const parseOriginBorrowIncentiveAccountData = (
584
+ utils: ScallopUtils,
584
585
  originBorrowIncentiveAccountData: OriginBorrowIncentiveAccountData
585
586
  ): ParsedBorrowIncentiveAccountData => {
586
587
  return {
@@ -591,9 +592,7 @@ export const parseOriginBorrowIncentiveAccountData = (
591
592
  pointList: originBorrowIncentiveAccountData.points_list.reduce(
592
593
  (acc, point) => {
593
594
  const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
594
- const name = parseStructTag(
595
- parsed.pointType
596
- ).name.toLowerCase() as string;
595
+ const name = utils.parseCoinNameFromType(parsed.pointType);
597
596
  acc[name] = parsed;
598
597
  return acc;
599
598
  },