@scallop-io/sui-scallop-sdk 2.0.0-alpha.3 → 2.0.0-alpha.5
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 +47 -2
- package/dist/index.d.ts +47 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/models/scallopCache.ts +2 -2
- package/src/models/scallopClient.ts +2 -6
- package/src/models/scallopConstants.ts +70 -25
- package/src/models/scallopUtils.ts +1 -1
- package/src/queries/portfolioQuery.ts +3 -11
- package/src/types/model.ts +0 -1
package/package.json
CHANGED
|
@@ -351,8 +351,8 @@ export class ScallopCache {
|
|
|
351
351
|
retryDelay: 1000,
|
|
352
352
|
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
353
353
|
queryFn: async () => {
|
|
354
|
-
const results = await this.callWithRateLimit(
|
|
355
|
-
|
|
354
|
+
const results = await this.callWithRateLimit(() =>
|
|
355
|
+
this.client.getOwnedObjects(input)
|
|
356
356
|
);
|
|
357
357
|
if (results && results.data.length > 0) {
|
|
358
358
|
results.data
|
|
@@ -493,9 +493,7 @@ export class ScallopClient {
|
|
|
493
493
|
const sender = walletAddress ?? this.walletAddress;
|
|
494
494
|
txBlock.setSender(sender);
|
|
495
495
|
|
|
496
|
-
const availableStake = (
|
|
497
|
-
[...this.constants.whitelist.lending] as readonly string[]
|
|
498
|
-
).includes(poolCoinName);
|
|
496
|
+
const availableStake = this.constants.whitelist.lending.has(poolCoinName);
|
|
499
497
|
if (sign && availableStake) {
|
|
500
498
|
await txBlock.unstakeObligationQuick(obligationId, obligationKey);
|
|
501
499
|
}
|
|
@@ -541,9 +539,7 @@ export class ScallopClient {
|
|
|
541
539
|
const sender = walletAddress ?? this.walletAddress;
|
|
542
540
|
txBlock.setSender(sender);
|
|
543
541
|
|
|
544
|
-
const availableStake = (
|
|
545
|
-
[...this.constants.whitelist.lending] as readonly string[]
|
|
546
|
-
).includes(poolCoinName);
|
|
542
|
+
const availableStake = this.constants.whitelist.lending.has(poolCoinName);
|
|
547
543
|
if (sign && availableStake) {
|
|
548
544
|
await txBlock.unstakeObligationQuick(obligationId, obligationKey);
|
|
549
545
|
}
|
|
@@ -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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
.
|
|
249
|
-
|
|
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
|
|
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)
|
|
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
|
|
|
@@ -312,12 +363,6 @@ export class ScallopConstants {
|
|
|
312
363
|
this._whitelist = params?.forceWhitelistInterface;
|
|
313
364
|
}
|
|
314
365
|
|
|
315
|
-
console.log({
|
|
316
|
-
isAddressInitialized: this.isAddressInitialized,
|
|
317
|
-
a: params?.forcePoolAddressInterface,
|
|
318
|
-
b: params?.forceWhitelistInterface,
|
|
319
|
-
isInitialized: this.isInitialized,
|
|
320
|
-
});
|
|
321
366
|
if (this.isInitialized) return;
|
|
322
367
|
|
|
323
368
|
const [whitelistResponse, poolAddressesResponse] = await Promise.all([
|
|
@@ -328,14 +373,14 @@ export class ScallopConstants {
|
|
|
328
373
|
if (!this.params.forceWhitelistInterface) {
|
|
329
374
|
this._whitelist = Object.fromEntries(
|
|
330
375
|
Object.entries(whitelistResponse)
|
|
331
|
-
.filter(([
|
|
376
|
+
.filter(([_, value]) => Array.isArray(value) || value instanceof Set)
|
|
332
377
|
.map(([key, value]) => [
|
|
333
378
|
key as keyof Whitelist,
|
|
334
|
-
|
|
379
|
+
value instanceof Set ? value : new Set(value),
|
|
335
380
|
])
|
|
336
381
|
) as Whitelist;
|
|
337
382
|
}
|
|
338
|
-
if (!this.params.forcePoolAddressInterface)
|
|
383
|
+
if (!this.params.forcePoolAddressInterface) {
|
|
339
384
|
this._poolAddresses = Object.fromEntries(
|
|
340
385
|
Object.entries(poolAddressesResponse)
|
|
341
386
|
.filter(([key]) =>
|
|
@@ -348,6 +393,6 @@ export class ScallopConstants {
|
|
|
348
393
|
return [key, parsedValue as PoolAddress];
|
|
349
394
|
})
|
|
350
395
|
);
|
|
351
|
-
|
|
396
|
+
}
|
|
352
397
|
}
|
|
353
398
|
}
|
|
@@ -439,9 +439,9 @@ export class ScallopUtils {
|
|
|
439
439
|
},
|
|
440
440
|
[] as [string, string][]
|
|
441
441
|
);
|
|
442
|
+
if (priceIdPairs.length === 0) break;
|
|
442
443
|
|
|
443
444
|
const priceIds = priceIdPairs.map(([_, priceId]) => priceId);
|
|
444
|
-
|
|
445
445
|
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
446
446
|
timeout: 4000,
|
|
447
447
|
});
|
|
@@ -42,9 +42,7 @@ export const getLendings = async (
|
|
|
42
42
|
query.utils.parseMarketCoinName(poolCoinName)
|
|
43
43
|
);
|
|
44
44
|
const stakeMarketCoinNames = marketCoinNames.filter((marketCoinName) =>
|
|
45
|
-
|
|
46
|
-
marketCoinName
|
|
47
|
-
)
|
|
45
|
+
query.constants.whitelist.spool.has(marketCoinName)
|
|
48
46
|
) as string[];
|
|
49
47
|
|
|
50
48
|
coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
|
|
@@ -139,10 +137,7 @@ export const getLending = async (
|
|
|
139
137
|
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
140
138
|
|
|
141
139
|
spool =
|
|
142
|
-
(spool ??
|
|
143
|
-
([...query.constants.whitelist.spool] as readonly string[]).includes(
|
|
144
|
-
marketCoinName
|
|
145
|
-
))
|
|
140
|
+
(spool ?? query.constants.whitelist.spool.has(marketCoinName))
|
|
146
141
|
? await query.getSpool(marketCoinName as string, {
|
|
147
142
|
indexer,
|
|
148
143
|
marketPool,
|
|
@@ -155,10 +150,7 @@ export const getLending = async (
|
|
|
155
150
|
// if (!spool) throw new Error(`Failed to fetch spool for ${poolCoinName}`);
|
|
156
151
|
|
|
157
152
|
stakeAccounts =
|
|
158
|
-
stakeAccounts ||
|
|
159
|
-
([...query.constants.whitelist.spool] as readonly string[]).includes(
|
|
160
|
-
marketCoinName
|
|
161
|
-
)
|
|
153
|
+
stakeAccounts || query.constants.whitelist.spool.has(marketCoinName)
|
|
162
154
|
? await query.getStakeAccounts(marketCoinName as string, ownerAddress)
|
|
163
155
|
: [];
|
|
164
156
|
coinAmount =
|
package/src/types/model.ts
CHANGED
|
@@ -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>>;
|