@scallop-io/sui-scallop-sdk 2.0.0-alpha.2 → 2.0.0-alpha.4
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 +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +14 -14
- package/dist/index.mjs +4 -4
- package/package.json +1 -1
- package/src/models/scallopCache.ts +2 -2
- package/src/models/scallopClient.ts +2 -6
- package/src/models/scallopConstants.ts +26 -22
- package/src/models/scallopUtils.ts +2 -2
- package/src/queries/borrowIncentiveQuery.ts +4 -2
- package/src/queries/poolAddressesQuery.ts +31 -11
- package/src/queries/portfolioQuery.ts +3 -12
- package/src/types/model.ts +1 -0
- package/src/utils/query.ts +3 -4
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
|
}
|
|
@@ -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
|
-
|
|
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.
|
|
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 ??
|
|
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/
|
|
297
|
+
`https://sui.apis.scallop.io/pool/addresses`,
|
|
309
298
|
queryKey: queryKeys.api.getPoolAddresses(),
|
|
310
299
|
});
|
|
311
300
|
}
|
|
@@ -329,14 +318,29 @@ export class ScallopConstants {
|
|
|
329
318
|
this.readWhiteList(),
|
|
330
319
|
this.readPoolAddresses(),
|
|
331
320
|
]);
|
|
321
|
+
|
|
332
322
|
if (!this.params.forceWhitelistInterface) {
|
|
333
|
-
this._whitelist =
|
|
323
|
+
this._whitelist = Object.fromEntries(
|
|
324
|
+
Object.entries(whitelistResponse)
|
|
325
|
+
.filter(([key]) => key !== 'id')
|
|
326
|
+
.map(([key, value]) => [
|
|
327
|
+
key as keyof Whitelist,
|
|
328
|
+
key !== 'id' ? new Set(value) : value,
|
|
329
|
+
])
|
|
330
|
+
) as Whitelist;
|
|
334
331
|
}
|
|
335
332
|
if (!this.params.forcePoolAddressInterface)
|
|
336
333
|
this._poolAddresses = Object.fromEntries(
|
|
337
|
-
Object.entries(poolAddressesResponse)
|
|
338
|
-
|
|
339
|
-
|
|
334
|
+
Object.entries(poolAddressesResponse)
|
|
335
|
+
.filter(([key]) =>
|
|
336
|
+
Object.values(this.whitelist).some((set) => set.has(key))
|
|
337
|
+
)
|
|
338
|
+
.map(([key, value]) => {
|
|
339
|
+
const parsedValue = Object.fromEntries(
|
|
340
|
+
Object.entries(value).map(([k, v]) => [k, v || undefined])
|
|
341
|
+
);
|
|
342
|
+
return [key, parsedValue as PoolAddress];
|
|
343
|
+
})
|
|
340
344
|
);
|
|
341
345
|
}
|
|
342
346
|
}
|
|
@@ -146,7 +146,7 @@ export class ScallopUtils {
|
|
|
146
146
|
if (useOldMarketCoin) {
|
|
147
147
|
return this.constants.coinNameToOldMarketCoinTypeMap[coinName] ?? '';
|
|
148
148
|
}
|
|
149
|
-
return this.constants.
|
|
149
|
+
return this.constants.coinTypes[coinName] ?? '';
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
/**
|
|
@@ -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
|
});
|
|
@@ -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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
...
|
|
250
|
-
...
|
|
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
|
-
|
|
257
|
-
pythFeedObjectId,
|
|
277
|
+
...pythData,
|
|
258
278
|
flashloanFeeObject: flashloanFeeObjectIds[coinType] ?? '',
|
|
259
279
|
};
|
|
260
280
|
|
|
@@ -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 =
|
|
@@ -549,7 +541,6 @@ export const getObligationAccount = async (
|
|
|
549
541
|
borrowIncentivePool.points[
|
|
550
542
|
query.utils.parseSCoinTypeNameToMarketCoinName(key)
|
|
551
543
|
];
|
|
552
|
-
|
|
553
544
|
if (accountPoint && poolPoint) {
|
|
554
545
|
let availableClaimAmount = BigNumber(0);
|
|
555
546
|
let availableClaimCoin = BigNumber(0);
|
package/src/types/model.ts
CHANGED
|
@@ -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>>;
|
package/src/utils/query.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { normalizeStructTag
|
|
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 =
|
|
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
|
},
|