@scallop-io/sui-scallop-sdk 0.47.3 → 0.47.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/constants/common.d.ts +6 -4
- package/dist/constants/enum.d.ts +1 -0
- package/dist/index.js +134 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -123
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +11 -3
- package/dist/models/scallopUtils.d.ts +4 -2
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -0
- package/dist/queries/coreQuery.d.ts +2 -0
- package/dist/queries/portfolioQuery.d.ts +1 -0
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/queries/vescaQuery.d.ts +1 -1
- package/dist/types/constant/common.d.ts +3 -1
- package/dist/types/constant/enum.d.ts +7 -1
- package/dist/utils/util.d.ts +3 -1
- package/package.json +1 -1
- package/src/constants/common.ts +15 -1
- package/src/constants/enum.ts +13 -0
- package/src/models/scallopClient.ts +3 -1
- package/src/models/scallopQuery.ts +8 -2
- package/src/models/scallopUtils.ts +52 -22
- package/src/queries/coreQuery.ts +0 -1
- package/src/queries/spoolQuery.ts +40 -103
- package/src/queries/vescaQuery.ts +8 -2
- package/src/types/constant/common.ts +4 -0
- package/src/types/constant/enum.ts +9 -0
- package/src/utils/util.ts +25 -3
|
@@ -272,18 +272,13 @@ export const getStakeAccounts = async (
|
|
|
272
272
|
}
|
|
273
273
|
} while (hasNextPage);
|
|
274
274
|
|
|
275
|
-
const stakeAccounts: StakeAccounts =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
safsui: [],
|
|
283
|
-
shasui: [],
|
|
284
|
-
svsui: [],
|
|
285
|
-
// ssca: [],
|
|
286
|
-
};
|
|
275
|
+
const stakeAccounts: StakeAccounts = SUPPORT_SPOOLS.reduce(
|
|
276
|
+
(acc, stakeName) => {
|
|
277
|
+
acc[stakeName] = [];
|
|
278
|
+
return acc;
|
|
279
|
+
},
|
|
280
|
+
{} as StakeAccounts
|
|
281
|
+
);
|
|
287
282
|
|
|
288
283
|
const stakeMarketCoinTypes: Record<SupportStakeMarketCoins, string> =
|
|
289
284
|
Object.keys(stakeAccounts).reduce(
|
|
@@ -300,6 +295,16 @@ export const getStakeAccounts = async (
|
|
|
300
295
|
{} as Record<SupportStakeMarketCoins, string>
|
|
301
296
|
);
|
|
302
297
|
|
|
298
|
+
// Reverse the mapping
|
|
299
|
+
const reversedStakeMarketCoinTypes: Record<string, SupportStakeMarketCoins> =
|
|
300
|
+
Object.entries(stakeMarketCoinTypes).reduce(
|
|
301
|
+
(reversedTypes, [key, value]) => {
|
|
302
|
+
reversedTypes[value] = key as SupportStakeMarketCoins;
|
|
303
|
+
return reversedTypes;
|
|
304
|
+
},
|
|
305
|
+
{} as Record<string, SupportStakeMarketCoins>
|
|
306
|
+
);
|
|
307
|
+
|
|
303
308
|
const stakeObjectIds: string[] = stakeObjectsResponse
|
|
304
309
|
.map((ref: any) => ref?.data?.objectId)
|
|
305
310
|
.filter((id: any) => id !== undefined);
|
|
@@ -318,98 +323,30 @@ export const getStakeAccounts = async (
|
|
|
318
323
|
const index = Number(fields.index);
|
|
319
324
|
const points = Number(fields.points);
|
|
320
325
|
const totalPoints = Number(fields.total_points);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
stakeAccounts.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.swusdc) {
|
|
344
|
-
stakeAccounts.swusdc.push({
|
|
345
|
-
id,
|
|
346
|
-
type: normalizeStructTag(type),
|
|
347
|
-
stakePoolId,
|
|
348
|
-
stakeType: normalizeStructTag(stakeType),
|
|
349
|
-
staked,
|
|
350
|
-
index,
|
|
351
|
-
points,
|
|
352
|
-
totalPoints,
|
|
353
|
-
});
|
|
354
|
-
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.swusdt) {
|
|
355
|
-
stakeAccounts.swusdt.push({
|
|
356
|
-
id,
|
|
357
|
-
type: normalizeStructTag(type),
|
|
358
|
-
stakePoolId,
|
|
359
|
-
stakeType: normalizeStructTag(stakeType),
|
|
360
|
-
staked,
|
|
361
|
-
index,
|
|
362
|
-
points,
|
|
363
|
-
totalPoints,
|
|
364
|
-
});
|
|
365
|
-
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.scetus) {
|
|
366
|
-
stakeAccounts.scetus.push({
|
|
367
|
-
id,
|
|
368
|
-
type: normalizeStructTag(type),
|
|
369
|
-
stakePoolId,
|
|
370
|
-
stakeType: normalizeStructTag(stakeType),
|
|
371
|
-
staked,
|
|
372
|
-
index,
|
|
373
|
-
points,
|
|
374
|
-
totalPoints,
|
|
375
|
-
});
|
|
376
|
-
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.safsui) {
|
|
377
|
-
stakeAccounts.safsui.push({
|
|
378
|
-
id,
|
|
379
|
-
type: normalizeStructTag(type),
|
|
380
|
-
stakePoolId,
|
|
381
|
-
stakeType: normalizeStructTag(stakeType),
|
|
382
|
-
staked,
|
|
383
|
-
index,
|
|
384
|
-
points,
|
|
385
|
-
totalPoints,
|
|
386
|
-
});
|
|
387
|
-
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.shasui) {
|
|
388
|
-
stakeAccounts.shasui.push({
|
|
389
|
-
id,
|
|
390
|
-
type: normalizeStructTag(type),
|
|
391
|
-
stakePoolId,
|
|
392
|
-
stakeType: normalizeStructTag(stakeType),
|
|
393
|
-
staked,
|
|
394
|
-
index,
|
|
395
|
-
points,
|
|
396
|
-
totalPoints,
|
|
397
|
-
});
|
|
398
|
-
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.svsui) {
|
|
399
|
-
stakeAccounts.svsui.push({
|
|
400
|
-
id,
|
|
401
|
-
type: normalizeStructTag(type),
|
|
402
|
-
stakePoolId,
|
|
403
|
-
stakeType: normalizeStructTag(stakeType),
|
|
404
|
-
staked,
|
|
405
|
-
index,
|
|
406
|
-
points,
|
|
407
|
-
totalPoints,
|
|
408
|
-
});
|
|
409
|
-
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.susdc) {
|
|
410
|
-
stakeAccounts.susdc.push({
|
|
326
|
+
|
|
327
|
+
const stakeMarketCoinTypeMap: Record<
|
|
328
|
+
SupportStakeMarketCoins,
|
|
329
|
+
StakeAccounts[SupportStakeMarketCoins]
|
|
330
|
+
> = {
|
|
331
|
+
sweth: stakeAccounts.sweth,
|
|
332
|
+
ssui: stakeAccounts.ssui,
|
|
333
|
+
swusdc: stakeAccounts.swusdc,
|
|
334
|
+
swusdt: stakeAccounts.swusdt,
|
|
335
|
+
scetus: stakeAccounts.scetus,
|
|
336
|
+
safsui: stakeAccounts.safsui,
|
|
337
|
+
shasui: stakeAccounts.shasui,
|
|
338
|
+
svsui: stakeAccounts.svsui,
|
|
339
|
+
susdc: stakeAccounts.susdc,
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const normalizedType = normalizeStructTag(type);
|
|
343
|
+
const stakeAccountArray =
|
|
344
|
+
stakeMarketCoinTypeMap[reversedStakeMarketCoinTypes[normalizedType]];
|
|
345
|
+
|
|
346
|
+
if (stakeAccountArray) {
|
|
347
|
+
stakeAccountArray.push({
|
|
411
348
|
id,
|
|
412
|
-
type:
|
|
349
|
+
type: normalizedType,
|
|
413
350
|
stakePoolId,
|
|
414
351
|
stakeType: normalizeStructTag(stakeType),
|
|
415
352
|
staked,
|
|
@@ -70,7 +70,8 @@ export const getVeScas = async (
|
|
|
70
70
|
}: {
|
|
71
71
|
utils: ScallopUtils;
|
|
72
72
|
},
|
|
73
|
-
ownerAddress?: string
|
|
73
|
+
ownerAddress?: string,
|
|
74
|
+
excludeEmpty?: boolean
|
|
74
75
|
) => {
|
|
75
76
|
const keyObjectDatas = await getVescaKeys(utils, ownerAddress);
|
|
76
77
|
|
|
@@ -83,9 +84,14 @@ export const getVeScas = async (
|
|
|
83
84
|
});
|
|
84
85
|
await Promise.allSettled(tasks);
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
const result = veScas
|
|
87
88
|
.filter(Boolean)
|
|
88
89
|
.sort((a, b) => b!.currentVeScaBalance - a!.currentVeScaBalance);
|
|
90
|
+
|
|
91
|
+
if (excludeEmpty) {
|
|
92
|
+
return result.filter((v) => v.lockedScaAmount !== '0');
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
89
95
|
};
|
|
90
96
|
|
|
91
97
|
const SuiObjectRefZod = zod.object({
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
9
9
|
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
10
10
|
SUPPORT_SCOIN,
|
|
11
|
+
SUPPORT_SUI_BRIDGE,
|
|
12
|
+
SUPPORT_WORMHOLE,
|
|
11
13
|
} from '../../constants';
|
|
12
14
|
|
|
13
15
|
type ParseMarketCoins<T extends string> = `s${T}`;
|
|
@@ -29,6 +31,8 @@ export type SupportMarketCoins =
|
|
|
29
31
|
| ParseMarketCoins<SupportPoolCoins>
|
|
30
32
|
| SupportStakeMarketCoins;
|
|
31
33
|
export type SupportStakeMarketCoins = (typeof SUPPORT_SPOOLS)[number];
|
|
34
|
+
export type SupportSuiBridgeCoins = (typeof SUPPORT_SUI_BRIDGE)[number];
|
|
35
|
+
export type SupportWormholeCoins = (typeof SUPPORT_WORMHOLE)[number];
|
|
32
36
|
export type SupportStakeCoins = Extract<
|
|
33
37
|
SupportPoolCoins,
|
|
34
38
|
ParseCoins<SupportStakeMarketCoins>
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
SupportBorrowIncentiveCoins,
|
|
8
8
|
SupportBorrowIncentiveRewardCoins,
|
|
9
9
|
SupportSCoin,
|
|
10
|
+
SupportSuiBridgeCoins,
|
|
10
11
|
} from './common';
|
|
11
12
|
|
|
12
13
|
export type Coins = {
|
|
@@ -33,6 +34,10 @@ export type StakeRewardCoins = {
|
|
|
33
34
|
[key in SupportStakeMarketCoins]: SupportStakeRewardCoins;
|
|
34
35
|
};
|
|
35
36
|
|
|
37
|
+
export type SuiBridgeCoins = {
|
|
38
|
+
[K in SupportSuiBridgeCoins]: K;
|
|
39
|
+
};
|
|
40
|
+
|
|
36
41
|
export type BorrowIncentiveRewardCoins = {
|
|
37
42
|
[key in SupportBorrowIncentiveCoins]: SupportBorrowIncentiveRewardCoins[];
|
|
38
43
|
};
|
|
@@ -65,3 +70,7 @@ export type WormholeCoinIds = {
|
|
|
65
70
|
export type VoloCoinIds = {
|
|
66
71
|
[key in PickFromUnion<SupportAssetCoins, 'vsui'>]: string;
|
|
67
72
|
};
|
|
73
|
+
|
|
74
|
+
export type SuiBridgedCoinPackageIds = {
|
|
75
|
+
[key in SupportSuiBridgeCoins]: string;
|
|
76
|
+
};
|
package/src/utils/util.ts
CHANGED
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
MAX_LOCK_DURATION,
|
|
7
7
|
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
8
8
|
SUPPORT_SCOIN,
|
|
9
|
+
SUPPORT_SUI_BRIDGE,
|
|
10
|
+
SUPPORT_WORMHOLE,
|
|
9
11
|
} from '../constants';
|
|
10
12
|
import type { ScallopAddress } from '../models';
|
|
11
13
|
import type {
|
|
12
14
|
SupportAssetCoins,
|
|
13
15
|
SupportCoins,
|
|
14
16
|
SupportMarketCoins,
|
|
17
|
+
SupportSuiBridgeCoins,
|
|
18
|
+
SupportWormholeCoins,
|
|
15
19
|
} from '../types';
|
|
16
20
|
|
|
17
21
|
const COIN_SET = Array.from(
|
|
@@ -33,11 +37,29 @@ export const isMarketCoin = (
|
|
|
33
37
|
);
|
|
34
38
|
};
|
|
35
39
|
|
|
36
|
-
export const
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
export const isSuiBridgeAsset = (
|
|
41
|
+
coinName: any
|
|
42
|
+
): coinName is SupportSuiBridgeCoins => {
|
|
43
|
+
return SUPPORT_SUI_BRIDGE.includes(coinName);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const isWormholeAsset = (
|
|
47
|
+
coinName: any
|
|
48
|
+
): coinName is SupportWormholeCoins => {
|
|
49
|
+
return SUPPORT_WORMHOLE.includes(coinName);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const parseAssetSymbol = (coinName: SupportCoins): string => {
|
|
53
|
+
if (isWormholeAsset(coinName)) {
|
|
39
54
|
return `w${coinName.slice(1).toUpperCase()}`;
|
|
40
55
|
}
|
|
56
|
+
if (isSuiBridgeAsset(coinName)) {
|
|
57
|
+
return `sb${coinName.slice(2).toUpperCase()}`;
|
|
58
|
+
}
|
|
59
|
+
if (isMarketCoin(coinName)) {
|
|
60
|
+
const assetCoinName = coinName.slice(1).toLowerCase() as SupportAssetCoins;
|
|
61
|
+
return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
|
|
62
|
+
}
|
|
41
63
|
switch (coinName) {
|
|
42
64
|
case 'afsui':
|
|
43
65
|
return 'afSUI';
|