@scallop-io/sui-scallop-sdk 2.0.8 → 2.0.9

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.8",
3
+ "version": "2.0.9",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -1092,12 +1092,12 @@ export class ScallopClient {
1092
1092
  */
1093
1093
  public async claimAllUnlockedSca(): Promise<SuiTransactionBlockResponse>;
1094
1094
  public async claimAllUnlockedSca<S extends boolean>(
1095
- walletAddress?: string,
1096
- sign?: S
1095
+ sign?: S,
1096
+ walletAddress?: string
1097
1097
  ): Promise<ScallopClientVeScaReturnType<S>>;
1098
1098
  public async claimAllUnlockedSca<S extends boolean>(
1099
- walletAddress?: string,
1100
- sign: S = true as S
1099
+ sign: S = true as S,
1100
+ walletAddress?: string
1101
1101
  ): Promise<ScallopClientVeScaReturnType<S>> {
1102
1102
  const sender = walletAddress ?? this.walletAddress;
1103
1103
  // get all veSca keys
@@ -42,6 +42,7 @@ export class ScallopConstants {
42
42
  oracles: new Set(),
43
43
  pythEndpoints: new Set(),
44
44
  deprecated: new Set(),
45
+ emerging: new Set(),
45
46
  };
46
47
 
47
48
  private _coinDecimals: Record<string, number | undefined> = {};
@@ -230,7 +230,6 @@ const queryRequiredMarketObjects = async (
230
230
  borrowFeeKey: query.constants.poolAddresses[t]?.borrowFeeKey,
231
231
  supplyLimitKey: query.constants.poolAddresses[t]?.supplyLimitKey,
232
232
  borrowLimitKey: query.constants.poolAddresses[t]?.borrowLimitKey,
233
- isolatedAssetKey: query.constants.poolAddresses[t]?.isolatedAssetKey,
234
233
  }));
235
234
 
236
235
  // Query all objects for each key in parallel
@@ -243,7 +242,6 @@ const queryRequiredMarketObjects = async (
243
242
  borrowFeeObjects,
244
243
  supplyLimitObjects,
245
244
  borrowLimitObjects,
246
- isolatedAssetObjects,
247
245
  ] = await Promise.all([
248
246
  queryMultipleObjects(
249
247
  query.cache,
@@ -277,15 +275,14 @@ const queryRequiredMarketObjects = async (
277
275
  query.cache,
278
276
  tasks.map((task) => task.borrowLimitKey).filter((t): t is string => !!t)
279
277
  ),
280
- queryMultipleObjects(
281
- query.cache,
282
- tasks.map((task) => task.isolatedAssetKey).filter((t): t is string => !!t)
283
- ),
284
278
  ]);
285
279
 
286
280
  // Map the results back to poolCoinNames
287
281
  const mapObjects = (
288
- tasks: { poolCoinName: string; [key: string]: string | undefined }[],
282
+ tasks: {
283
+ poolCoinName: string;
284
+ [key: string]: string | undefined;
285
+ }[],
289
286
  fetchedObjects: SuiObjectData[],
290
287
  keyValue: string
291
288
  ) => {
@@ -338,11 +335,11 @@ const queryRequiredMarketObjects = async (
338
335
  borrowLimitObjects,
339
336
  'borrowLimitKey'
340
337
  );
341
- const isolatedAssetMap = mapObjects(
342
- tasks,
343
- isolatedAssetObjects,
344
- 'isolatedAssetKey'
345
- );
338
+ // const isolatedAssetMap = mapObjects(
339
+ // tasks,
340
+ // isolatedAssetObjects,
341
+ // 'isolatedAssetKey'
342
+ // );
346
343
  // Construct the final requiredObjects result
347
344
  const result = poolCoinNames.reduce(
348
345
  (acc, name) => {
@@ -355,7 +352,8 @@ const queryRequiredMarketObjects = async (
355
352
  borrowFeeKey: borrowFeeMap[name],
356
353
  supplyLimitKey: supplyLimitMap[name],
357
354
  borrowLimitKey: borrowLimitMap[name],
358
- isolatedAssetKey: isolatedAssetMap[name],
355
+ isolatedAssetKey:
356
+ query.constants.poolAddresses[name]?.isolatedAssetKey ?? false,
359
357
  };
360
358
  return acc;
361
359
  },
@@ -370,7 +368,7 @@ const queryRequiredMarketObjects = async (
370
368
  borrowFeeKey: SuiObjectData;
371
369
  supplyLimitKey: SuiObjectData;
372
370
  borrowLimitKey: SuiObjectData;
373
- isolatedAssetKey: SuiObjectData;
371
+ isolatedAssetKey: boolean;
374
372
  }
375
373
  >
376
374
  );
@@ -484,7 +482,7 @@ const parseMarketPoolObjects = ({
484
482
  borrowFeeKey?: SuiObjectData;
485
483
  supplyLimitKey?: SuiObjectData;
486
484
  borrowLimitKey?: SuiObjectData;
487
- isolatedAssetKey: SuiObjectData;
485
+ isolatedAssetKey: boolean;
488
486
  }): OriginMarketPoolData & {
489
487
  parsedOriginMarketCollateral?: OriginMarketCollateralData;
490
488
  } => {
@@ -511,7 +509,7 @@ const parseMarketPoolObjects = ({
511
509
  _riskModel && _collateralStat
512
510
  ? {
513
511
  type: _interestModel.type.fields,
514
- isIsolated: !!isolatedAssetKey,
512
+ isIsolated: isolatedAssetKey,
515
513
  collateralFactor: _riskModel.collateral_factor.fields,
516
514
  liquidationFactor: _riskModel.liquidation_factor.fields,
517
515
  liquidationPenalty: _riskModel.liquidation_penalty.fields,
@@ -572,7 +570,7 @@ export const getMarketPool = async (
572
570
  borrowFeeKey: SuiObjectData;
573
571
  supplyLimitKey: SuiObjectData;
574
572
  borrowLimitKey: SuiObjectData;
575
- isolatedAssetKey: SuiObjectData;
573
+ isolatedAssetKey: boolean;
576
574
  }
577
575
  ): Promise<
578
576
  { marketPool: MarketPool; collateral?: MarketCollateral } | undefined
@@ -90,7 +90,7 @@ export const isIsolatedAsset = async (
90
90
  ): Promise<boolean> => {
91
91
  const assetInPoolAddresses = utils.constants.poolAddresses[coinName];
92
92
  if (assetInPoolAddresses) {
93
- return !!assetInPoolAddresses.isolatedAssetKey;
93
+ return assetInPoolAddresses.isolatedAssetKey;
94
94
  }
95
95
 
96
96
  const marketObject = utils.address.get('core.market');
@@ -1,4 +1,4 @@
1
- import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
1
+ import { getFullnodeUrl, SuiClient, SuiParsedData } from '@mysten/sui/client';
2
2
  import { AddressesInterface, OptionalKeys, PoolAddress } from 'src/types';
3
3
 
4
4
  const RPC_PROVIDERS = [
@@ -62,6 +62,31 @@ const queryFlashloanFeeObjectIds = async (
62
62
  return flashloanFeeObjectIds;
63
63
  };
64
64
 
65
+ type FetchDynamicObjectReturnType<T extends boolean> = T extends true
66
+ ? string | undefined
67
+ : (SuiParsedData & { dataType: 'moveObject' }) | null | undefined;
68
+
69
+ const fetchDynamicObject = async <S extends boolean>(
70
+ parentId: string,
71
+ type: string,
72
+ value: any,
73
+ returnObjId: S = true as S
74
+ ): Promise<FetchDynamicObjectReturnType<S>> => {
75
+ const res = (
76
+ await tryRequest(async (client) => {
77
+ return await client.getDynamicFieldObject({
78
+ parentId,
79
+ name: {
80
+ type,
81
+ value,
82
+ },
83
+ });
84
+ })
85
+ ).data;
86
+ if (returnObjId) return res?.objectId as FetchDynamicObjectReturnType<S>;
87
+ else return res?.content as FetchDynamicObjectReturnType<S>;
88
+ };
89
+
65
90
  export const getPoolAddresses = async (
66
91
  addressId: string,
67
92
  poolNames: string[] = []
@@ -133,23 +158,6 @@ export const getPoolAddresses = async (
133
158
  const SUPPLY_LIMIT_TYPE = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey`;
134
159
  const BORROW_LIMIT_TYPE = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`; // prod
135
160
  const ISOLATED_ASSET_KEY = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::IsolatedAssetKey`;
136
- const fetchDynamicObject = async (
137
- parentId: string,
138
- type: string,
139
- value: any
140
- ) => {
141
- return (
142
- await tryRequest(async (client) => {
143
- return await client.getDynamicFieldObject({
144
- parentId,
145
- name: {
146
- type,
147
- value,
148
- },
149
- });
150
- })
151
- ).data?.objectId;
152
- };
153
161
 
154
162
  // query flashloan fee objects first
155
163
  const flashloanFeeObjectIds = await tryRequest(async (client) => {
@@ -163,25 +171,50 @@ export const getPoolAddresses = async (
163
171
  coinTypesPairs.map(async ([coinName, coinType]) => {
164
172
  const coinTypeKey = coinType.slice(2);
165
173
  const addresses = await Promise.all([
166
- fetchDynamicObject(balanceSheetParentId, ADDRESS_TYPE, {
167
- name: coinTypeKey,
168
- }),
169
- fetchDynamicObject(collateralStatsParentId, ADDRESS_TYPE, {
170
- name: coinTypeKey,
171
- }),
172
- fetchDynamicObject(borrowDynamicsParentid, ADDRESS_TYPE, {
173
- name: coinTypeKey,
174
- }),
175
- fetchDynamicObject(interestModelParentId, ADDRESS_TYPE, {
176
- name: coinTypeKey,
177
- }),
178
- fetchDynamicObject(riskModelParentId, ADDRESS_TYPE, {
179
- name: coinTypeKey,
180
- }),
181
- fetchDynamicObject(marketId, BORROW_FEE_TYPE, coinTypeKey),
182
- fetchDynamicObject(marketId, SUPPLY_LIMIT_TYPE, coinTypeKey),
183
- fetchDynamicObject(marketId, BORROW_LIMIT_TYPE, coinTypeKey),
184
- fetchDynamicObject(marketId, ISOLATED_ASSET_KEY, coinTypeKey),
174
+ fetchDynamicObject(
175
+ balanceSheetParentId,
176
+ ADDRESS_TYPE,
177
+ {
178
+ name: coinTypeKey,
179
+ },
180
+ true
181
+ ),
182
+ fetchDynamicObject(
183
+ collateralStatsParentId,
184
+ ADDRESS_TYPE,
185
+ {
186
+ name: coinTypeKey,
187
+ },
188
+ true
189
+ ),
190
+ fetchDynamicObject(
191
+ borrowDynamicsParentid,
192
+ ADDRESS_TYPE,
193
+ {
194
+ name: coinTypeKey,
195
+ },
196
+ true
197
+ ),
198
+ fetchDynamicObject(
199
+ interestModelParentId,
200
+ ADDRESS_TYPE,
201
+ {
202
+ name: coinTypeKey,
203
+ },
204
+ true
205
+ ),
206
+ fetchDynamicObject(
207
+ riskModelParentId,
208
+ ADDRESS_TYPE,
209
+ {
210
+ name: coinTypeKey,
211
+ },
212
+ true
213
+ ),
214
+ fetchDynamicObject(marketId, BORROW_FEE_TYPE, coinTypeKey, true),
215
+ fetchDynamicObject(marketId, SUPPLY_LIMIT_TYPE, coinTypeKey, true),
216
+ fetchDynamicObject(marketId, BORROW_LIMIT_TYPE, coinTypeKey, true),
217
+ fetchDynamicObject(marketId, ISOLATED_ASSET_KEY, coinTypeKey, false),
185
218
  ]);
186
219
 
187
220
  // @ts-ignore
@@ -263,7 +296,7 @@ export const getPoolAddresses = async (
263
296
  borrowFeeKey: addresses[5] ?? '',
264
297
  supplyLimitKey: addresses[6] ?? '',
265
298
  borrowLimitKey: addresses[7] ?? '',
266
- isolatedAssetKey: addresses[8] ?? '',
299
+ isolatedAssetKey: (addresses[8]?.fields as any)?.value ?? false,
267
300
  ...spoolData,
268
301
  ...sCoinData,
269
302
  sCoinName,
@@ -22,7 +22,7 @@ export type PoolAddress = {
22
22
  sCoinSymbol?: string;
23
23
  sCoinMetadataId?: string;
24
24
  sCoinTreasury?: string;
25
- isolatedAssetKey?: string;
25
+ isolatedAssetKey: boolean;
26
26
  spool?: string;
27
27
  spoolReward?: string;
28
28
  spoolName?: string;
@@ -42,6 +42,7 @@ export type Whitelist = {
42
42
  rewardsAsPoint: Set<string>;
43
43
  pythEndpoints: Set<string>;
44
44
  deprecated: Set<string>;
45
+ emerging: Set<string>;
45
46
  };
46
47
 
47
48
  export type CoinWrappedType =