@scallop-io/sui-scallop-sdk 1.4.13 → 1.4.14-alpha.1
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/tokenBucket.d.ts +1 -1
- package/dist/index.js +47 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -32
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopCache.d.ts +1 -0
- package/dist/models/scallopUtils.d.ts +4 -2
- package/dist/utils/query.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants/enum.ts +14 -6
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopCache.ts +12 -7
- package/src/models/scallopUtils.ts +10 -3
- package/src/queries/borrowIncentiveQuery.ts +5 -7
- package/src/queries/borrowLimitQuery.ts +2 -2
- package/src/queries/isolatedAssetQuery.ts +2 -2
- package/src/queries/portfolioQuery.ts +6 -1
- package/src/queries/supplyLimitQuery.ts +2 -2
- package/src/utils/query.ts +5 -7
- package/src/utils/tokenBucket.ts +1 -1
|
@@ -38,6 +38,7 @@ export declare class ScallopCache {
|
|
|
38
38
|
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
39
39
|
*/
|
|
40
40
|
invalidateAllCache(): Promise<Promise<void>[]>;
|
|
41
|
+
private retryFn;
|
|
41
42
|
/**
|
|
42
43
|
* @description Provides cache for inspectTxn of the SuiKit.
|
|
43
44
|
* @param QueryInspectTxnParams
|
|
@@ -59,12 +59,13 @@ export declare class ScallopUtils {
|
|
|
59
59
|
*/
|
|
60
60
|
parseSCoinName<T extends SupportSCoin>(coinName: SupportCoins | SupportMarketCoins): T | undefined;
|
|
61
61
|
/**
|
|
62
|
-
* Convert sCoin name to coin name.
|
|
62
|
+
* Convert sCoin name to market coin name.
|
|
63
63
|
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
64
64
|
* e.g: `scallop_sui -> ssui
|
|
65
|
+
* if no `scallop_...` is encountered, return coinName
|
|
65
66
|
* @return sCoin name
|
|
66
67
|
*/
|
|
67
|
-
|
|
68
|
+
parseSCoinTypeNameToMarketCoinName(coinName: string): "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep";
|
|
68
69
|
/**
|
|
69
70
|
* Convert sCoin name into sCoin type
|
|
70
71
|
* @param sCoinName
|
|
@@ -110,6 +111,7 @@ export declare class ScallopUtils {
|
|
|
110
111
|
parseCoinNameFromType<T extends SupportAssetCoins>(coinType: string): T extends SupportAssetCoins ? T : SupportAssetCoins;
|
|
111
112
|
parseCoinNameFromType<T extends SupportMarketCoins>(coinType: string): T extends SupportMarketCoins ? T : SupportMarketCoins;
|
|
112
113
|
parseCoinNameFromType<T extends SupportCoins>(coinType: string): T extends SupportCoins ? T : SupportCoins;
|
|
114
|
+
parseCoinNameFromType<T extends SupportSCoin>(coinType: string): T extends SupportSCoin ? T : SupportSCoin;
|
|
113
115
|
/**
|
|
114
116
|
* Convert market coin name to coin name.
|
|
115
117
|
*
|
package/dist/utils/query.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare const parseOriginBorrowIncentivesPoolPointData: (originBorrowInce
|
|
|
40
40
|
* @param originBorrowIncentivePoolData - Origin borrow incentive pool data
|
|
41
41
|
* @return Parsed borrow incentive pool data
|
|
42
42
|
*/
|
|
43
|
-
export declare const parseOriginBorrowIncentivePoolData: (originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
|
|
43
|
+
export declare const parseOriginBorrowIncentivePoolData: (utils: ScallopUtils, originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
|
|
44
44
|
export declare const calculateBorrowIncentivePoolPointData: (parsedBorrowIncentivePoolPointData: ParsedBorrowIncentivePoolPointData, rewardCoinPrice: number, rewardCoinDecimal: number, poolCoinPrice: number, poolCoinDecimal: number) => CalculatedBorrowIncentivePoolPointData;
|
|
45
45
|
export declare const parseOriginBorrowIncentiveAccountPoolPointData: (originBorrowIncentiveAccountPoolPointData: OriginBorrowIncentiveAccountPoolData) => ParsedBorrowIncentiveAccountPoolData;
|
|
46
46
|
/**
|
package/package.json
CHANGED
package/src/constants/enum.ts
CHANGED
|
@@ -157,16 +157,24 @@ export const voloCoinIds: types.VoloCoinIds = {
|
|
|
157
157
|
|
|
158
158
|
// PROD VERSION
|
|
159
159
|
export const sCoinIds: types.SCoinIds = {
|
|
160
|
+
// prod values
|
|
161
|
+
// ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
162
|
+
// swusdc:
|
|
163
|
+
// '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
164
|
+
// swusdt:
|
|
165
|
+
// '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
166
|
+
// ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
167
|
+
|
|
168
|
+
ssui: '0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI',
|
|
169
|
+
swusdt:
|
|
170
|
+
'0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
171
|
+
swusdc:
|
|
172
|
+
'0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
173
|
+
ssca: '0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA',
|
|
160
174
|
susdc:
|
|
161
175
|
'0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC',
|
|
162
176
|
ssbeth:
|
|
163
177
|
'0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH',
|
|
164
|
-
ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
165
|
-
swusdc:
|
|
166
|
-
'0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
167
|
-
swusdt:
|
|
168
|
-
'0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
169
|
-
ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
170
178
|
scetus:
|
|
171
179
|
'0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS',
|
|
172
180
|
sweth:
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
2
|
-
export const DEFAULT_INTERVAL_IN_MS =
|
|
2
|
+
export const DEFAULT_INTERVAL_IN_MS = 250;
|
|
@@ -106,6 +106,11 @@ export class ScallopCache {
|
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
private retryFn(errCount: number, err: any) {
|
|
110
|
+
if (err.status === 429) return true;
|
|
111
|
+
if (errCount >= 5) return false;
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
109
114
|
/**
|
|
110
115
|
* @description Provides cache for inspectTxn of the SuiKit.
|
|
111
116
|
* @param QueryInspectTxnParams
|
|
@@ -122,7 +127,7 @@ export class ScallopCache {
|
|
|
122
127
|
txBlock.moveCall(queryTarget, args, typeArgs);
|
|
123
128
|
|
|
124
129
|
const query = await this.queryClient.fetchQuery({
|
|
125
|
-
retry:
|
|
130
|
+
retry: this.retryFn,
|
|
126
131
|
retryDelay: 1000,
|
|
127
132
|
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
128
133
|
queryFn: async () => {
|
|
@@ -146,7 +151,7 @@ export class ScallopCache {
|
|
|
146
151
|
options?: SuiObjectDataOptions
|
|
147
152
|
): Promise<SuiObjectResponse | null> {
|
|
148
153
|
return this.queryClient.fetchQuery({
|
|
149
|
-
retry:
|
|
154
|
+
retry: this.retryFn,
|
|
150
155
|
retryDelay: 1000,
|
|
151
156
|
queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
|
|
152
157
|
queryFn: async () => {
|
|
@@ -177,7 +182,7 @@ export class ScallopCache {
|
|
|
177
182
|
// objectIds.sort();
|
|
178
183
|
|
|
179
184
|
return this.queryClient.fetchQuery({
|
|
180
|
-
retry:
|
|
185
|
+
retry: this.retryFn,
|
|
181
186
|
retryDelay: 1000,
|
|
182
187
|
queryKey: queryKeys.rpc.getObjects(
|
|
183
188
|
objectIds,
|
|
@@ -200,7 +205,7 @@ export class ScallopCache {
|
|
|
200
205
|
*/
|
|
201
206
|
public async queryGetOwnedObjects(input: GetOwnedObjectsParams) {
|
|
202
207
|
return this.queryClient.fetchQuery({
|
|
203
|
-
retry:
|
|
208
|
+
retry: this.retryFn,
|
|
204
209
|
retryDelay: 1000,
|
|
205
210
|
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
206
211
|
queryFn: async () => {
|
|
@@ -216,7 +221,7 @@ export class ScallopCache {
|
|
|
216
221
|
input: GetDynamicFieldsParams
|
|
217
222
|
): Promise<DynamicFieldPage | null> {
|
|
218
223
|
return this.queryClient.fetchQuery({
|
|
219
|
-
retry:
|
|
224
|
+
retry: this.retryFn,
|
|
220
225
|
retryDelay: 1000,
|
|
221
226
|
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
222
227
|
queryFn: async () => {
|
|
@@ -232,7 +237,7 @@ export class ScallopCache {
|
|
|
232
237
|
input: GetDynamicFieldObjectParams
|
|
233
238
|
): Promise<SuiObjectResponse | null> {
|
|
234
239
|
return this.queryClient.fetchQuery({
|
|
235
|
-
retry:
|
|
240
|
+
retry: this.retryFn,
|
|
236
241
|
retryDelay: (attemptIndex) => Math.min(1000 * attemptIndex, 8000),
|
|
237
242
|
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
238
243
|
queryFn: async () => {
|
|
@@ -247,7 +252,7 @@ export class ScallopCache {
|
|
|
247
252
|
owner: string
|
|
248
253
|
): Promise<{ [k: string]: string }> {
|
|
249
254
|
return this.queryClient.fetchQuery({
|
|
250
|
-
retry:
|
|
255
|
+
retry: this.retryFn,
|
|
251
256
|
retryDelay: 1000,
|
|
252
257
|
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
253
258
|
queryFn: async () => {
|
|
@@ -232,13 +232,14 @@ export class ScallopUtils {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
/**
|
|
235
|
-
* Convert sCoin name to coin name.
|
|
235
|
+
* Convert sCoin name to market coin name.
|
|
236
236
|
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
237
237
|
* e.g: `scallop_sui -> ssui
|
|
238
|
+
* if no `scallop_...` is encountered, return coinName
|
|
238
239
|
* @return sCoin name
|
|
239
240
|
*/
|
|
240
|
-
public
|
|
241
|
-
return sCoinRawNameToName[coinName];
|
|
241
|
+
public parseSCoinTypeNameToMarketCoinName(coinName: string) {
|
|
242
|
+
return sCoinRawNameToName[coinName] ?? coinName;
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
/**
|
|
@@ -311,8 +312,14 @@ export class ScallopUtils {
|
|
|
311
312
|
public parseCoinNameFromType<T extends SupportCoins>(
|
|
312
313
|
coinType: string
|
|
313
314
|
): T extends SupportCoins ? T : SupportCoins;
|
|
315
|
+
public parseCoinNameFromType<T extends SupportSCoin>(
|
|
316
|
+
coinType: string
|
|
317
|
+
): T extends SupportSCoin ? T : SupportSCoin;
|
|
314
318
|
public parseCoinNameFromType(coinType: string) {
|
|
315
319
|
coinType = normalizeStructTag(coinType);
|
|
320
|
+
if (sCoinTypeToName[coinType]) {
|
|
321
|
+
return sCoinTypeToName[coinType] as SupportSCoin;
|
|
322
|
+
}
|
|
316
323
|
|
|
317
324
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
318
325
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
2
|
import {
|
|
3
|
-
sCoinRawNameToName,
|
|
4
3
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
5
4
|
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
6
5
|
} from '../constants';
|
|
@@ -100,8 +99,10 @@ export const getBorrowIncentivePools = async (
|
|
|
100
99
|
const borrowIncentivePoolPoints: OptionalKeys<
|
|
101
100
|
Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
|
|
102
101
|
> = {};
|
|
103
|
-
const parsedBorrowIncentivePoolData =
|
|
104
|
-
|
|
102
|
+
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
|
|
103
|
+
query.utils,
|
|
104
|
+
pool
|
|
105
|
+
);
|
|
105
106
|
|
|
106
107
|
const poolCoinType = normalizeStructTag(pool.pool_type.name);
|
|
107
108
|
const poolCoinName =
|
|
@@ -121,13 +122,10 @@ export const getBorrowIncentivePools = async (
|
|
|
121
122
|
parsedBorrowIncentivePoolData.poolPoints
|
|
122
123
|
)) {
|
|
123
124
|
const rewardCoinType = poolPoint.pointType;
|
|
124
|
-
|
|
125
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
125
126
|
rewardCoinType
|
|
126
127
|
) as SupportBorrowIncentiveRewardCoins;
|
|
127
128
|
// handle for scoin name
|
|
128
|
-
if (sCoinRawNameToName[rewardCoinName]) {
|
|
129
|
-
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
130
|
-
}
|
|
131
129
|
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
132
130
|
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
133
131
|
|
|
@@ -17,8 +17,8 @@ const borrowLimitZod = zod.object({
|
|
|
17
17
|
}),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
const borrowLimitKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`; // prod
|
|
21
|
-
|
|
20
|
+
// const borrowLimitKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`; // prod
|
|
21
|
+
const borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Return supply limit of a pool (including the decimals)
|
|
@@ -18,8 +18,8 @@ const isolatedAssetZod = zod.object({
|
|
|
18
18
|
}),
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
const isolatedAssetKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::IsolatedAssetKey`; // prod
|
|
22
|
-
|
|
21
|
+
// const isolatedAssetKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::IsolatedAssetKey`; // prod
|
|
22
|
+
const isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Return list of isolated assets coin types
|
|
@@ -532,7 +532,7 @@ export const getObligationAccount = async (
|
|
|
532
532
|
([key, accountPoint]) => {
|
|
533
533
|
const poolPoint =
|
|
534
534
|
borrowIncentivePool.points[
|
|
535
|
-
key
|
|
535
|
+
query.utils.parseSCoinTypeNameToMarketCoinName(key)
|
|
536
536
|
];
|
|
537
537
|
|
|
538
538
|
if (accountPoint && poolPoint) {
|
|
@@ -577,6 +577,11 @@ export const getObligationAccount = async (
|
|
|
577
577
|
.toNumber()
|
|
578
578
|
: 1;
|
|
579
579
|
|
|
580
|
+
// console.log({
|
|
581
|
+
// availableClaimAmount: availableClaimAmount.toString(),
|
|
582
|
+
// coinName: poolPoint.coinName,
|
|
583
|
+
// coinType: poolPoint.coinType,
|
|
584
|
+
// });
|
|
580
585
|
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
581
586
|
rewards.push({
|
|
582
587
|
coinName: poolPoint.coinName,
|
|
@@ -17,8 +17,8 @@ const supplyLimitZod = zod.object({
|
|
|
17
17
|
}),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
const supplyLimitKeyType = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey`; // prod
|
|
21
|
-
|
|
20
|
+
// const supplyLimitKeyType = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey`; // prod
|
|
21
|
+
const supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
|
|
22
22
|
/**
|
|
23
23
|
* Return supply limit of a pool (including the decimals)
|
|
24
24
|
* @param utils
|
package/src/utils/query.ts
CHANGED
|
@@ -27,7 +27,6 @@ import type {
|
|
|
27
27
|
ParsedBorrowIncentiveAccountPoolData,
|
|
28
28
|
SupportBorrowIncentiveRewardCoins,
|
|
29
29
|
} from '../types';
|
|
30
|
-
import { sCoinRawNameToName } from 'src/constants';
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
32
|
* Parse origin market pool data to a more readable format.
|
|
@@ -424,6 +423,7 @@ export const parseOriginBorrowIncentivesPoolPointData = (
|
|
|
424
423
|
* @return Parsed borrow incentive pool data
|
|
425
424
|
*/
|
|
426
425
|
export const parseOriginBorrowIncentivePoolData = (
|
|
426
|
+
utils: ScallopUtils,
|
|
427
427
|
originBorrowIncentivePoolData: OriginBorrowIncentivePoolData
|
|
428
428
|
): ParsedBorrowIncentivePoolData => {
|
|
429
429
|
return {
|
|
@@ -434,12 +434,10 @@ export const parseOriginBorrowIncentivePoolData = (
|
|
|
434
434
|
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
435
435
|
(acc, point) => {
|
|
436
436
|
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
437
|
-
|
|
438
|
-
parsed.pointType
|
|
439
|
-
)
|
|
440
|
-
|
|
441
|
-
name = sCoinRawNameToName[name];
|
|
442
|
-
}
|
|
437
|
+
const name = utils.parseSCoinTypeNameToMarketCoinName(
|
|
438
|
+
parseStructTag(parsed.pointType).name.toLowerCase()
|
|
439
|
+
) as SupportBorrowIncentiveRewardCoins;
|
|
440
|
+
|
|
443
441
|
acc[name] = parsed;
|
|
444
442
|
return acc;
|
|
445
443
|
},
|
package/src/utils/tokenBucket.ts
CHANGED
|
@@ -42,7 +42,7 @@ const callWithRateLimit = async <T>(
|
|
|
42
42
|
fn: () => Promise<T>,
|
|
43
43
|
retryDelayInMs = DEFAULT_INTERVAL_IN_MS,
|
|
44
44
|
maxRetries = 15,
|
|
45
|
-
backoffFactor =
|
|
45
|
+
backoffFactor = 1.25 // The factor by which to increase the delay
|
|
46
46
|
): Promise<T | null> => {
|
|
47
47
|
let retries = 0;
|
|
48
48
|
|