@scallop-io/sui-scallop-sdk 2.0.0-alpha.4 → 2.0.0-alpha.6

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.4",
3
+ "version": "2.0.0-alpha.6",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -56,6 +56,7 @@ export class ScallopConstants {
56
56
  private _coinTypes: Record<string, string | undefined> = {};
57
57
  private _sCoinTypes: Record<string, string | undefined> = {};
58
58
  private _coinTypeToCoinNameMap: Record<string, string | undefined> = {};
59
+ private _supportedBorrowIncentiveRewards: Set<string> = new Set();
59
60
 
60
61
  constructor(
61
62
  public readonly params: ScallopConstantsParams,
@@ -127,6 +128,10 @@ export class ScallopConstants {
127
128
  );
128
129
  }
129
130
 
131
+ /**
132
+ * @description
133
+ * Return maps of coin names to coin decimals.
134
+ */
130
135
  get coinDecimals() {
131
136
  if (this.isEmptyObject(this._coinDecimals)) {
132
137
  this._coinDecimals = Object.fromEntries([
@@ -141,6 +146,10 @@ export class ScallopConstants {
141
146
  return this._coinDecimals;
142
147
  }
143
148
 
149
+ /**
150
+ * @description
151
+ * Return maps of coin names to coin types.
152
+ */
144
153
  get coinTypes() {
145
154
  if (this.isEmptyObject(this._coinTypes))
146
155
  this._coinTypes = Object.fromEntries([
@@ -154,6 +163,22 @@ export class ScallopConstants {
154
163
  return this._coinTypes;
155
164
  }
156
165
 
166
+ /**
167
+ * @description
168
+ * Return maps of coin types to its coin name
169
+ */
170
+ get coinTypeToCoinNameMap() {
171
+ if (this.isEmptyObject(this._coinTypeToCoinNameMap))
172
+ this._coinTypeToCoinNameMap = Object.fromEntries(
173
+ Object.entries(this.coinTypes).map(([key, val]) => [val, key])
174
+ );
175
+ return this._coinTypeToCoinNameMap;
176
+ }
177
+
178
+ /**
179
+ * @description
180
+ * Return maps of wormhole coin types to its coin name.
181
+ */
157
182
  get wormholeCoinTypeToCoinName() {
158
183
  if (this.isEmptyObject(this._wormholeCoinTypeToCoinNameMap))
159
184
  this._wormholeCoinTypeToCoinNameMap = Object.fromEntries(
@@ -164,14 +189,10 @@ export class ScallopConstants {
164
189
  return this._wormholeCoinTypeToCoinNameMap;
165
190
  }
166
191
 
167
- get coinTypeToCoinNameMap() {
168
- if (this.isEmptyObject(this._coinTypeToCoinNameMap))
169
- this._coinTypeToCoinNameMap = Object.fromEntries(
170
- Object.entries(this.coinTypes).map(([key, val]) => [val, key])
171
- );
172
- return this._coinTypeToCoinNameMap;
173
- }
174
-
192
+ /**
193
+ * @description
194
+ * Return maps of coin name to its old market coin type (...::reserve::MarketCoin<coinType>)
195
+ */
175
196
  get coinNameToOldMarketCoinTypeMap() {
176
197
  if (this.isEmptyObject(this._coinNameToOldMarketCoinTypeMap))
177
198
  this._coinNameToOldMarketCoinTypeMap = Object.fromEntries(
@@ -185,6 +206,10 @@ export class ScallopConstants {
185
206
  return this._coinNameToOldMarketCoinTypeMap;
186
207
  }
187
208
 
209
+ /**
210
+ * @description
211
+ * Return maps of sCoin raw name from its type to its sCoin name. (e.g. 'scallop_sui' -> 'ssui')
212
+ */
188
213
  get sCoinRawNameToScoinNameMap() {
189
214
  if (this.isEmptyObject(this._scoinRawNameToSCoinNameMap))
190
215
  this._scoinRawNameToSCoinNameMap = Object.fromEntries(
@@ -199,6 +224,10 @@ export class ScallopConstants {
199
224
  return this._scoinRawNameToSCoinNameMap;
200
225
  }
201
226
 
227
+ /**
228
+ * @description
229
+ * Return maps of scoin type to its sCoin name
230
+ */
202
231
  get sCoinTypeToSCoinNameMap() {
203
232
  if (this.isEmptyObject(this._scoinTypeToSCoinNameMap))
204
233
  this._scoinTypeToSCoinNameMap = Object.fromEntries(
@@ -210,6 +239,10 @@ export class ScallopConstants {
210
239
  return this._scoinTypeToSCoinNameMap;
211
240
  }
212
241
 
242
+ /**
243
+ * @description
244
+ * Return maps of volo coin type to its coin name
245
+ */
213
246
  get voloCoinTypeToCoinNameMap() {
214
247
  if (this.isEmptyObject(this._voloCoinTypeToCoinNameMap))
215
248
  this._voloCoinTypeToCoinNameMap = {
@@ -218,6 +251,10 @@ export class ScallopConstants {
218
251
  return this._voloCoinTypeToCoinNameMap;
219
252
  }
220
253
 
254
+ /**
255
+ * @description
256
+ * Return maps of sui bridge coin type to its coin name
257
+ */
221
258
  get suiBridgeCoinTypeToCoinNameMap() {
222
259
  if (this.isEmptyObject(this._suiBridgeCoinTypeToCoinNameMap))
223
260
  this._suiBridgeCoinTypeToCoinNameMap = Object.fromEntries(
@@ -231,6 +268,10 @@ export class ScallopConstants {
231
268
  return this._suiBridgeCoinTypeToCoinNameMap;
232
269
  }
233
270
 
271
+ /**
272
+ * @description
273
+ * Return maps of sCoin coin name to its coin type
274
+ */
234
275
  get sCoinTypes() {
235
276
  if (this.isEmptyObject(this._sCoinTypes))
236
277
  this._sCoinTypes = Object.fromEntries(
@@ -242,12 +283,20 @@ export class ScallopConstants {
242
283
  return this._sCoinTypes;
243
284
  }
244
285
 
286
+ /**
287
+ * @description
288
+ * Return set of supported coin types for borrow incentive rewards
289
+ * (all supported pools + sCoins + custom coins from `whitelist.borrowIncentiveRewards`)
290
+ */
245
291
  get supportedBorrowIncentiveRewards() {
246
- return new Set([
247
- ...Object.values(this.poolAddresses)
248
- .filter((t) => !!t)
249
- .map((t) => t?.coinName),
250
- ]);
292
+ if (!this._supportedBorrowIncentiveRewards.size)
293
+ this._supportedBorrowIncentiveRewards = new Set([
294
+ ...Object.values(this.poolAddresses)
295
+ .filter((t) => !!t)
296
+ .map((t) => (t.sCoinName ? [t.coinName, t.sCoinName] : [t.coinName]))
297
+ .flat(),
298
+ ]);
299
+ return this._supportedBorrowIncentiveRewards;
251
300
  }
252
301
 
253
302
  private isEmptyObject(obj: Record<string, unknown>) {
@@ -281,12 +330,14 @@ export class ScallopConstants {
281
330
  const response = await this.readApi<Record<keyof Whitelist, string[]>>({
282
331
  url:
283
332
  this.params.whitelistApiUrl ??
284
- `https://sui.apis.scallop.io/pool/whitelist/${this.params.whitelistId}`,
333
+ `https://sui.apis.scallop.io/pool/whitelist`,
285
334
  queryKey: queryKeys.api.getWhiteList(),
286
335
  });
287
336
 
288
337
  return Object.fromEntries(
289
- Object.entries(response).map(([key, value]) => [key, new Set(value)])
338
+ Object.entries(response)
339
+ .filter(([_, value]) => Array.isArray(value))
340
+ .map(([key, value]) => [key, new Set(value)])
290
341
  ) as Whitelist;
291
342
  }
292
343
 
@@ -322,14 +373,14 @@ export class ScallopConstants {
322
373
  if (!this.params.forceWhitelistInterface) {
323
374
  this._whitelist = Object.fromEntries(
324
375
  Object.entries(whitelistResponse)
325
- .filter(([key]) => key !== 'id')
376
+ .filter(([_, value]) => Array.isArray(value) || value instanceof Set)
326
377
  .map(([key, value]) => [
327
378
  key as keyof Whitelist,
328
- key !== 'id' ? new Set(value) : value,
379
+ value instanceof Set ? value : new Set(value),
329
380
  ])
330
381
  ) as Whitelist;
331
382
  }
332
- if (!this.params.forcePoolAddressInterface)
383
+ if (!this.params.forcePoolAddressInterface) {
333
384
  this._poolAddresses = Object.fromEntries(
334
385
  Object.entries(poolAddressesResponse)
335
386
  .filter(([key]) =>
@@ -342,5 +393,6 @@ export class ScallopConstants {
342
393
  return [key, parsedValue as PoolAddress];
343
394
  })
344
395
  );
396
+ }
345
397
  }
346
398
  }
@@ -251,7 +251,10 @@ export class ScallopUtils {
251
251
 
252
252
  if (isMarketCoinType) {
253
253
  return this.parseMarketCoinName(
254
- parseStructTag(typeParams as any).name.toLowerCase()
254
+ (typeof typeParams[0] === 'string'
255
+ ? parseStructTag(typeParams[0])
256
+ : typeParams[0]
257
+ ).name.toLowerCase()
255
258
  );
256
259
  }
257
260
  const assetCoinName =
@@ -84,7 +84,6 @@ export type ScallopIndexerParams = ScallopCacheParams & {
84
84
  export type ScallopAddressParams = ScallopCacheParams & {
85
85
  addressApiUrl?: string;
86
86
  addressId: string;
87
- whitelistId: string;
88
87
  auth?: string;
89
88
  network?: NetworkType;
90
89
  forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;