@scallop-io/sui-scallop-sdk 1.4.14-alpha.1 → 1.4.15-rc.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/poolAddress.d.ts +14 -4
- package/dist/constants/queryKeys.d.ts +1 -2
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +714 -316
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +669 -271
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +20 -17
- package/dist/queries/coreQuery.d.ts +18 -19
- package/dist/queries/index.d.ts +2 -0
- package/dist/queries/isolatedAssetQuery.d.ts +2 -2
- package/dist/queries/objectsQuery.d.ts +3 -0
- package/dist/queries/poolAddressesQuery.d.ts +15 -0
- package/dist/types/query/core.d.ts +22 -5
- package/dist/types/utils.d.ts +7 -2
- package/dist/utils/core.d.ts +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/util.d.ts +1 -0
- package/package.json +1 -1
- package/src/constants/enum.ts +6 -14
- package/src/constants/poolAddress.ts +290 -29
- package/src/constants/queryKeys.ts +5 -5
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopCache.ts +34 -7
- package/src/models/scallopQuery.ts +24 -12
- package/src/queries/borrowIncentiveQuery.ts +1 -1
- package/src/queries/borrowLimitQuery.ts +2 -2
- package/src/queries/coreQuery.ts +378 -248
- package/src/queries/index.ts +2 -0
- package/src/queries/isolatedAssetQuery.ts +39 -33
- package/src/queries/objectsQuery.ts +20 -0
- package/src/queries/poolAddressesQuery.ts +134 -0
- package/src/queries/portfolioQuery.ts +14 -7
- package/src/queries/priceQuery.ts +3 -1
- package/src/queries/spoolQuery.ts +3 -1
- package/src/queries/supplyLimitQuery.ts +2 -2
- package/src/types/query/core.ts +21 -5
- package/src/types/utils.ts +8 -3
- package/src/utils/core.ts +11 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/query.ts +16 -2
- package/src/utils/tokenBucket.ts +1 -1
- package/src/utils/util.ts +8 -0
package/src/queries/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DynamicFieldInfo, DynamicFieldName } from '@mysten/sui/client';
|
|
2
|
-
import {
|
|
2
|
+
import { ScallopQuery, ScallopUtils } from '../models';
|
|
3
3
|
import { SupportPoolCoins } from '../types';
|
|
4
4
|
import { z as zod } from 'zod';
|
|
5
|
+
import { POOL_ADDRESSES, SUPPORT_POOLS } from 'src/constants';
|
|
5
6
|
|
|
6
7
|
const isolatedAssetZod = zod.object({
|
|
7
8
|
dataType: zod.string(),
|
|
@@ -18,8 +19,8 @@ const isolatedAssetZod = zod.object({
|
|
|
18
19
|
}),
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
const isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
|
|
22
|
+
const isolatedAssetKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::IsolatedAssetKey`; // prod
|
|
23
|
+
// const isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Return list of isolated assets coin types
|
|
@@ -27,10 +28,16 @@ const isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d
|
|
|
27
28
|
* @returns list of isolated assets coin types
|
|
28
29
|
*/
|
|
29
30
|
export const getIsolatedAssets = async (
|
|
30
|
-
|
|
31
|
+
query: ScallopQuery
|
|
31
32
|
): Promise<string[]> => {
|
|
33
|
+
if (SUPPORT_POOLS.every((t) => !!POOL_ADDRESSES[t])) {
|
|
34
|
+
return SUPPORT_POOLS.filter(
|
|
35
|
+
(t): t is typeof t & { coinType: string; isolatedAssetKey: string } =>
|
|
36
|
+
!!POOL_ADDRESSES[t]?.isolatedAssetKey && !!POOL_ADDRESSES[t]?.coinType
|
|
37
|
+
).map((t) => POOL_ADDRESSES[t as SupportPoolCoins]?.coinType!);
|
|
38
|
+
}
|
|
32
39
|
try {
|
|
33
|
-
const marketObject = address.get('core.market');
|
|
40
|
+
const marketObject = query.address.get('core.market');
|
|
34
41
|
const isolatedAssets: string[] = [];
|
|
35
42
|
if (!marketObject) return isolatedAssets;
|
|
36
43
|
|
|
@@ -46,7 +53,7 @@ export const getIsolatedAssets = async (
|
|
|
46
53
|
};
|
|
47
54
|
|
|
48
55
|
do {
|
|
49
|
-
const response = await
|
|
56
|
+
const response = await query.cache.queryGetDynamicFields({
|
|
50
57
|
parentId: marketObject,
|
|
51
58
|
cursor: nextCursor,
|
|
52
59
|
limit: 10,
|
|
@@ -81,34 +88,33 @@ export const isIsolatedAsset = async (
|
|
|
81
88
|
utils: ScallopUtils,
|
|
82
89
|
coinName: SupportPoolCoins
|
|
83
90
|
): Promise<boolean> => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
if (POOL_ADDRESSES[coinName]) {
|
|
92
|
+
return !!POOL_ADDRESSES[coinName].isolatedAssetKey;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const marketObject = utils.address.get('core.market');
|
|
96
|
+
// check if the coin type is in the list
|
|
97
|
+
const cachedData = utils.address.cache.queryClient.getQueryData<string[]>([
|
|
98
|
+
'getDynamicFields',
|
|
99
|
+
marketObject,
|
|
100
|
+
]);
|
|
101
|
+
if (cachedData) {
|
|
102
|
+
const coinType = utils.parseCoinType(coinName);
|
|
103
|
+
return cachedData.includes(coinType);
|
|
104
|
+
}
|
|
95
105
|
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
// fetch dynamic field object
|
|
107
|
+
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
98
108
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
110
|
+
parentId: marketObject,
|
|
111
|
+
name: {
|
|
112
|
+
type: isolatedAssetKeyType,
|
|
113
|
+
value: coinType,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
106
116
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
} catch (e) {
|
|
111
|
-
console.error(e);
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
117
|
+
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
118
|
+
if (!parsedData.success) return false;
|
|
119
|
+
return parsedData.data.fields.value;
|
|
114
120
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SuiObjectDataOptions } from '@mysten/sui/dist/cjs/client';
|
|
2
|
+
import { ScallopCache } from 'src/models/scallopCache';
|
|
3
|
+
import { partitionArray } from 'src/utils';
|
|
4
|
+
|
|
5
|
+
export const queryMultipleObjects = async (
|
|
6
|
+
cache: ScallopCache,
|
|
7
|
+
objectIds: string[],
|
|
8
|
+
options?: SuiObjectDataOptions,
|
|
9
|
+
partitionSize = 50
|
|
10
|
+
) => {
|
|
11
|
+
const objectIdsPartition = partitionArray(objectIds, partitionSize);
|
|
12
|
+
|
|
13
|
+
const objects = [];
|
|
14
|
+
for (const objectIds of objectIdsPartition) {
|
|
15
|
+
const result = await cache.queryGetObjects(objectIds, options);
|
|
16
|
+
objects.push(...result);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return objects;
|
|
20
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { SUPPORT_POOLS } from 'src/constants';
|
|
2
|
+
import { ScallopQuery } from 'src/models';
|
|
3
|
+
import { OptionalKeys, SupportPoolCoins, SupportSCoin } from 'src/types';
|
|
4
|
+
|
|
5
|
+
export const getAllAddresses = async (query: ScallopQuery) => {
|
|
6
|
+
const results: OptionalKeys<
|
|
7
|
+
Record<
|
|
8
|
+
SupportPoolCoins,
|
|
9
|
+
{
|
|
10
|
+
lendingPoolAddress?: string;
|
|
11
|
+
collateralPoolAddress?: string; // not all pool has collateral
|
|
12
|
+
borrowDynamic?: string;
|
|
13
|
+
spoolReward?: string;
|
|
14
|
+
spool?: string;
|
|
15
|
+
interestModel?: string;
|
|
16
|
+
riskModel?: string;
|
|
17
|
+
borrowFeeKey?: string;
|
|
18
|
+
supplyLimitKey?: string;
|
|
19
|
+
borrowLimitKey?: string;
|
|
20
|
+
isolatedAssetKey?: string;
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
> = {};
|
|
24
|
+
|
|
25
|
+
const marketId = query.address.get('core.market');
|
|
26
|
+
const marketObject = (
|
|
27
|
+
await query.cache.queryGetObject(marketId, {
|
|
28
|
+
showContent: true,
|
|
29
|
+
})
|
|
30
|
+
)?.data;
|
|
31
|
+
|
|
32
|
+
if (!(marketObject && marketObject.content?.dataType === 'moveObject'))
|
|
33
|
+
throw new Error(`Failed to fetch marketObject`);
|
|
34
|
+
|
|
35
|
+
const fields = marketObject.content.fields as any;
|
|
36
|
+
|
|
37
|
+
const coinTypesPairs = SUPPORT_POOLS.reduce(
|
|
38
|
+
(acc, pool) => {
|
|
39
|
+
acc.push([pool, query.utils.parseCoinType(pool).substring(2)]);
|
|
40
|
+
return acc;
|
|
41
|
+
},
|
|
42
|
+
[] as [SupportPoolCoins, string][]
|
|
43
|
+
);
|
|
44
|
+
const balanceSheetParentId =
|
|
45
|
+
fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
46
|
+
|
|
47
|
+
const collateralStatsParentId =
|
|
48
|
+
fields.collateral_stats.fields.table.fields.id.id;
|
|
49
|
+
|
|
50
|
+
const borrowDynamicsParentid =
|
|
51
|
+
fields.borrow_dynamics.fields.table.fields.id.id;
|
|
52
|
+
|
|
53
|
+
const interestModelParentId =
|
|
54
|
+
fields.interest_models.fields.table.fields.id.id;
|
|
55
|
+
|
|
56
|
+
const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
|
|
57
|
+
|
|
58
|
+
const ADDRESS_TYPE = `0x1::type_name::TypeName`;
|
|
59
|
+
const BORROW_FEE_TYPE = `0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da::market_dynamic_keys::BorrowFeeKey`;
|
|
60
|
+
const SUPPLY_LIMIT_TYPE = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey`;
|
|
61
|
+
const BORROW_LIMIT_TYPE = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`; // prod
|
|
62
|
+
const ISOLATED_ASSET_KEY = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::IsolatedAssetKey`;
|
|
63
|
+
const fetchDynamicObject = async (
|
|
64
|
+
parentId: string,
|
|
65
|
+
type: string,
|
|
66
|
+
value: any
|
|
67
|
+
) => {
|
|
68
|
+
try {
|
|
69
|
+
return (
|
|
70
|
+
await query.cache.queryGetDynamicFieldObject({
|
|
71
|
+
parentId,
|
|
72
|
+
name: {
|
|
73
|
+
type,
|
|
74
|
+
value,
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
)?.data?.objectId;
|
|
78
|
+
} catch (_e) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
await Promise.all(
|
|
84
|
+
coinTypesPairs.map(async ([coinName, coinType]) => {
|
|
85
|
+
const addresses = await Promise.all([
|
|
86
|
+
fetchDynamicObject(balanceSheetParentId, ADDRESS_TYPE, {
|
|
87
|
+
name: coinType,
|
|
88
|
+
}),
|
|
89
|
+
fetchDynamicObject(collateralStatsParentId, ADDRESS_TYPE, {
|
|
90
|
+
name: coinType,
|
|
91
|
+
}),
|
|
92
|
+
fetchDynamicObject(borrowDynamicsParentid, ADDRESS_TYPE, {
|
|
93
|
+
name: coinType,
|
|
94
|
+
}),
|
|
95
|
+
fetchDynamicObject(interestModelParentId, ADDRESS_TYPE, {
|
|
96
|
+
name: coinType,
|
|
97
|
+
}),
|
|
98
|
+
fetchDynamicObject(riskModelParentId, ADDRESS_TYPE, {
|
|
99
|
+
name: coinType,
|
|
100
|
+
}),
|
|
101
|
+
fetchDynamicObject(marketId, BORROW_FEE_TYPE, coinType),
|
|
102
|
+
fetchDynamicObject(marketId, SUPPLY_LIMIT_TYPE, coinType),
|
|
103
|
+
fetchDynamicObject(marketId, BORROW_LIMIT_TYPE, coinType),
|
|
104
|
+
fetchDynamicObject(marketId, ISOLATED_ASSET_KEY, coinType),
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
const spool = query.address.get(
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
`spool.pools.s${coinName as SupportSCoin}.id`
|
|
110
|
+
);
|
|
111
|
+
const rewardPool = query.address.get(
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
`spool.pools.s${coinName}.rewardPoolId`
|
|
114
|
+
);
|
|
115
|
+
results[coinName as SupportPoolCoins] = {
|
|
116
|
+
lendingPoolAddress: addresses[0],
|
|
117
|
+
collateralPoolAddress: addresses[1],
|
|
118
|
+
borrowDynamic: addresses[2],
|
|
119
|
+
interestModel: addresses[3],
|
|
120
|
+
riskModel: addresses[4],
|
|
121
|
+
borrowFeeKey: addresses[5],
|
|
122
|
+
supplyLimitKey: addresses[6],
|
|
123
|
+
borrowLimitKey: addresses[7],
|
|
124
|
+
isolatedAssetKey: addresses[8],
|
|
125
|
+
spool,
|
|
126
|
+
spoolReward: rewardPool,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return results;
|
|
134
|
+
};
|
|
@@ -51,10 +51,13 @@ export const getLendings = async (
|
|
|
51
51
|
) as SupportStakeMarketCoins[];
|
|
52
52
|
|
|
53
53
|
const coinPrices = await query.utils.getCoinPrices();
|
|
54
|
-
const marketPools =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const marketPools = (
|
|
55
|
+
await query.getMarketPools(poolCoinNames, {
|
|
56
|
+
indexer,
|
|
57
|
+
coinPrices,
|
|
58
|
+
})
|
|
59
|
+
).pools;
|
|
60
|
+
|
|
58
61
|
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
59
62
|
indexer,
|
|
60
63
|
marketPools,
|
|
@@ -309,7 +312,8 @@ export const getObligationAccounts = async (
|
|
|
309
312
|
indexer: boolean = false
|
|
310
313
|
) => {
|
|
311
314
|
const coinPrices = await query.utils.getCoinPrices();
|
|
312
|
-
const market = await query.queryMarket({ indexer, coinPrices });
|
|
315
|
+
// const market = await query.queryMarket({ indexer, coinPrices });
|
|
316
|
+
const market = await query.getMarketPools(undefined, { coinPrices, indexer });
|
|
313
317
|
const [coinAmounts, obligations] = await Promise.all([
|
|
314
318
|
query.getCoinAmounts(undefined, ownerAddress),
|
|
315
319
|
query.getObligations(ownerAddress),
|
|
@@ -357,7 +361,8 @@ export const getObligationAccount = async (
|
|
|
357
361
|
...SUPPORT_COLLATERALS,
|
|
358
362
|
] as SupportCollateralCoins[];
|
|
359
363
|
|
|
360
|
-
market = market ?? (await query.queryMarket({ indexer }));
|
|
364
|
+
// market = market ?? (await query.queryMarket({ indexer }));
|
|
365
|
+
market = market ?? (await query.getMarketPools(undefined, { indexer }));
|
|
361
366
|
coinPrices =
|
|
362
367
|
coinPrices ?? (await query.getAllCoinPrices({ marketPools: market.pools }));
|
|
363
368
|
coinAmounts =
|
|
@@ -784,7 +789,8 @@ export const getTotalValueLocked = async (
|
|
|
784
789
|
query: ScallopQuery,
|
|
785
790
|
indexer: boolean = false
|
|
786
791
|
) => {
|
|
787
|
-
const market = await query.queryMarket({ indexer });
|
|
792
|
+
// const market = await query.queryMarket({ indexer });
|
|
793
|
+
const market = await query.getMarketPools(undefined, { indexer });
|
|
788
794
|
|
|
789
795
|
let supplyValue = BigNumber(0);
|
|
790
796
|
let borrowValue = BigNumber(0);
|
|
@@ -811,6 +817,7 @@ export const getTotalValueLocked = async (
|
|
|
811
817
|
);
|
|
812
818
|
}
|
|
813
819
|
|
|
820
|
+
// console.dir(market.collaterals, { depth: null });
|
|
814
821
|
for (const collateral of Object.values(market.collaterals)) {
|
|
815
822
|
supplyValue = supplyValue.plus(
|
|
816
823
|
BigNumber(collateral.depositCoin).multipliedBy(collateral.coinPrice)
|
|
@@ -142,7 +142,9 @@ export const getAllCoinPrices = async (
|
|
|
142
142
|
) => {
|
|
143
143
|
coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
|
|
144
144
|
marketPools =
|
|
145
|
-
marketPools ??
|
|
145
|
+
marketPools ??
|
|
146
|
+
(await query.getMarketPools(undefined, { coinPrices })).pools;
|
|
147
|
+
|
|
146
148
|
if (!marketPools) {
|
|
147
149
|
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
148
150
|
}
|
|
@@ -43,7 +43,9 @@ export const getSpools = async (
|
|
|
43
43
|
coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
|
|
44
44
|
|
|
45
45
|
marketPools =
|
|
46
|
-
marketPools ??
|
|
46
|
+
marketPools ??
|
|
47
|
+
(await query.getMarketPools(stakeCoinNames, { indexer })).pools;
|
|
48
|
+
|
|
47
49
|
if (!marketPools)
|
|
48
50
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
49
51
|
|
|
@@ -17,8 +17,8 @@ const supplyLimitZod = zod.object({
|
|
|
17
17
|
}),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
const supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
|
|
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/types/query/core.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type BalanceSheet = {
|
|
|
28
28
|
revenue: string;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export type
|
|
31
|
+
export type BorrowDynamic = {
|
|
32
32
|
borrow_index: string;
|
|
33
33
|
interest_rate: {
|
|
34
34
|
fields: {
|
|
@@ -39,6 +39,8 @@ export type BorrowIndex = {
|
|
|
39
39
|
last_updated: string;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
export type BorrowFee = { value: string };
|
|
43
|
+
|
|
42
44
|
export type InterestModel = {
|
|
43
45
|
base_borrow_rate_per_sec: {
|
|
44
46
|
fields: {
|
|
@@ -161,7 +163,7 @@ export type MarketCollateral = {
|
|
|
161
163
|
| 'collateralFactor'
|
|
162
164
|
| 'liquidationFactor'
|
|
163
165
|
| 'liquidationDiscount'
|
|
164
|
-
| '
|
|
166
|
+
| 'liquidationPenalty'
|
|
165
167
|
| 'liquidationReserveFactor'
|
|
166
168
|
>
|
|
167
169
|
> &
|
|
@@ -187,6 +189,9 @@ export type OriginMarketPoolData = {
|
|
|
187
189
|
highKink: { value: string };
|
|
188
190
|
midKink: { value: string };
|
|
189
191
|
minBorrowAmount: string;
|
|
192
|
+
isIsolated: boolean;
|
|
193
|
+
supplyLimit: string;
|
|
194
|
+
borrowLimit: string;
|
|
190
195
|
};
|
|
191
196
|
|
|
192
197
|
export type ParsedMarketPoolData = {
|
|
@@ -209,6 +214,9 @@ export type ParsedMarketPoolData = {
|
|
|
209
214
|
highKink: number;
|
|
210
215
|
midKink: number;
|
|
211
216
|
minBorrowAmount: number;
|
|
217
|
+
isIsolated: boolean;
|
|
218
|
+
supplyLimit: number;
|
|
219
|
+
borrowLimit: number;
|
|
212
220
|
};
|
|
213
221
|
|
|
214
222
|
export type CalculatedMarketPoolData = {
|
|
@@ -218,6 +226,8 @@ export type CalculatedMarketPoolData = {
|
|
|
218
226
|
borrowApyOnHighKink: number;
|
|
219
227
|
borrowAprOnMidKink: number;
|
|
220
228
|
borrowApyOnMidKink: number;
|
|
229
|
+
coinDecimal: number;
|
|
230
|
+
conversionRate: number;
|
|
221
231
|
maxBorrowApr: number;
|
|
222
232
|
maxBorrowApy: number;
|
|
223
233
|
borrowApr: number;
|
|
@@ -233,15 +243,18 @@ export type CalculatedMarketPoolData = {
|
|
|
233
243
|
utilizationRate: number;
|
|
234
244
|
supplyApr: number;
|
|
235
245
|
supplyApy: number;
|
|
236
|
-
|
|
246
|
+
isIsolated: boolean;
|
|
247
|
+
maxSupplyCoin: number;
|
|
248
|
+
maxBorrowCoin: number;
|
|
237
249
|
};
|
|
238
250
|
|
|
239
251
|
export type OriginMarketCollateralData = {
|
|
240
252
|
type: { name: string };
|
|
253
|
+
isIsolated: boolean;
|
|
241
254
|
collateralFactor: { value: string };
|
|
242
255
|
liquidationFactor: { value: string };
|
|
243
256
|
liquidationDiscount: { value: string };
|
|
244
|
-
|
|
257
|
+
liquidationPenalty: { value: string };
|
|
245
258
|
liquidationReserveFactor: { value: string };
|
|
246
259
|
maxCollateralAmount: string;
|
|
247
260
|
totalCollateralAmount: string;
|
|
@@ -252,13 +265,16 @@ export type ParsedMarketCollateralData = {
|
|
|
252
265
|
collateralFactor: number;
|
|
253
266
|
liquidationFactor: number;
|
|
254
267
|
liquidationDiscount: number;
|
|
255
|
-
|
|
268
|
+
liquidationPenalty: number;
|
|
256
269
|
liquidationReserveFactor: number;
|
|
257
270
|
maxCollateralAmount: number;
|
|
258
271
|
totalCollateralAmount: number;
|
|
272
|
+
isIsolated: boolean;
|
|
259
273
|
};
|
|
260
274
|
|
|
261
275
|
export type CalculatedMarketCollateralData = {
|
|
276
|
+
coinDecimal: number;
|
|
277
|
+
isIsolated: boolean;
|
|
262
278
|
maxDepositAmount: number;
|
|
263
279
|
maxDepositCoin: number;
|
|
264
280
|
depositAmount: number;
|
package/src/types/utils.ts
CHANGED
|
@@ -11,10 +11,15 @@ export type PoolAddressInfo = {
|
|
|
11
11
|
coingeckoId: string;
|
|
12
12
|
decimal: number;
|
|
13
13
|
pythFeedId: string;
|
|
14
|
-
lendingPoolAddress
|
|
15
|
-
collateralPoolAddress?: string;
|
|
14
|
+
lendingPoolAddress?: string;
|
|
15
|
+
collateralPoolAddress?: string; // not all pool has collateral
|
|
16
|
+
borrowDynamic?: string;
|
|
17
|
+
interestModelId?: string;
|
|
18
|
+
borrowFeeKey?: string;
|
|
19
|
+
supplyLimitKey?: string;
|
|
20
|
+
borrowLimitKey?: string;
|
|
21
|
+
isolatedAssetKey?: string;
|
|
16
22
|
sCoinAddress: string | undefined;
|
|
17
23
|
marketCoinAddress: string;
|
|
18
|
-
coinAddress: string;
|
|
19
24
|
sCoinName: string | undefined;
|
|
20
25
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
|
+
|
|
3
|
+
export const parseObjectAs = <T>(object: SuiObjectData): T => {
|
|
4
|
+
if (!(object && object.content && 'fields' in object.content))
|
|
5
|
+
throw new Error(`Failed to parse object`);
|
|
6
|
+
|
|
7
|
+
const value = (object.content.fields as any).value;
|
|
8
|
+
if (typeof value === 'object' && 'fields' in value)
|
|
9
|
+
return (object.content.fields as any).value.fields as T;
|
|
10
|
+
return value as T;
|
|
11
|
+
};
|
package/src/utils/index.ts
CHANGED
package/src/utils/query.ts
CHANGED
|
@@ -62,6 +62,9 @@ export const parseOriginMarketPoolData = (
|
|
|
62
62
|
highKink: Number(originMarketPoolData.highKink.value) / 2 ** 32,
|
|
63
63
|
midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
|
|
64
64
|
minBorrowAmount: Number(originMarketPoolData.minBorrowAmount),
|
|
65
|
+
isIsolated: originMarketPoolData.isIsolated,
|
|
66
|
+
supplyLimit: Number(originMarketPoolData.supplyLimit),
|
|
67
|
+
borrowLimit: Number(originMarketPoolData.borrowLimit),
|
|
65
68
|
};
|
|
66
69
|
};
|
|
67
70
|
|
|
@@ -142,6 +145,7 @@ export const calculateMarketPoolData = (
|
|
|
142
145
|
borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
|
|
143
146
|
borrowAprOnMidKink,
|
|
144
147
|
borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
|
|
148
|
+
coinDecimal,
|
|
145
149
|
maxBorrowApr,
|
|
146
150
|
maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
|
|
147
151
|
borrowApr: Math.min(borrowApr, maxBorrowApr),
|
|
@@ -161,6 +165,13 @@ export const calculateMarketPoolData = (
|
|
|
161
165
|
supplyApr: supplyApr.toNumber(),
|
|
162
166
|
supplyApy: utils.parseAprToApy(supplyApr.toNumber()),
|
|
163
167
|
conversionRate: conversionRate.toNumber(),
|
|
168
|
+
isIsolated: parsedMarketPoolData.isIsolated,
|
|
169
|
+
maxSupplyCoin: BigNumber(parsedMarketPoolData.supplyLimit)
|
|
170
|
+
.shiftedBy(coinDecimal)
|
|
171
|
+
.toNumber(),
|
|
172
|
+
maxBorrowCoin: BigNumber(parsedMarketPoolData.borrowLimit)
|
|
173
|
+
.shiftedBy(coinDecimal)
|
|
174
|
+
.toNumber(),
|
|
164
175
|
};
|
|
165
176
|
};
|
|
166
177
|
|
|
@@ -176,14 +187,15 @@ export const parseOriginMarketCollateralData = (
|
|
|
176
187
|
const divisor = 2 ** 32;
|
|
177
188
|
return {
|
|
178
189
|
coinType: normalizeStructTag(originMarketCollateralData.type.name),
|
|
190
|
+
isIsolated: originMarketCollateralData.isIsolated,
|
|
179
191
|
collateralFactor:
|
|
180
192
|
Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
181
193
|
liquidationFactor:
|
|
182
194
|
Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
183
195
|
liquidationDiscount:
|
|
184
196
|
Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
185
|
-
|
|
186
|
-
Number(originMarketCollateralData.
|
|
197
|
+
liquidationPenalty:
|
|
198
|
+
Number(originMarketCollateralData.liquidationPenalty.value) / divisor,
|
|
187
199
|
liquidationReserveFactor:
|
|
188
200
|
Number(originMarketCollateralData.liquidationReserveFactor.value) /
|
|
189
201
|
divisor,
|
|
@@ -212,6 +224,8 @@ export const calculateMarketCollateralData = (
|
|
|
212
224
|
).shiftedBy(-1 * coinDecimal);
|
|
213
225
|
|
|
214
226
|
return {
|
|
227
|
+
coinDecimal,
|
|
228
|
+
isIsolated: parsedMarketCollateralData.isIsolated,
|
|
215
229
|
maxDepositAmount: parsedMarketCollateralData.maxCollateralAmount,
|
|
216
230
|
maxDepositCoin: maxCollateralCoin.toNumber(),
|
|
217
231
|
depositAmount: parsedMarketCollateralData.totalCollateralAmount,
|
package/src/utils/tokenBucket.ts
CHANGED
|
@@ -53,7 +53,7 @@ const callWithRateLimit = async <T>(
|
|
|
53
53
|
} else if (retries < maxRetries) {
|
|
54
54
|
retries++;
|
|
55
55
|
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
56
|
-
console.error(`Rate limit exceeded, retrying in ${delay} ms`);
|
|
56
|
+
// console.error(`Rate limit exceeded, retrying in ${delay} ms`);
|
|
57
57
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
58
58
|
return tryRequest();
|
|
59
59
|
} else {
|
package/src/utils/util.ts
CHANGED
|
@@ -127,3 +127,11 @@ export const findClosestUnlockRound = (unlockAtInSecondTimestamp: number) => {
|
|
|
127
127
|
}
|
|
128
128
|
return Math.floor(closestTwelveAM.getTime() / 1000);
|
|
129
129
|
};
|
|
130
|
+
|
|
131
|
+
export const partitionArray = <T>(array: T[], chunkSize: number) => {
|
|
132
|
+
const result: T[][] = [];
|
|
133
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
134
|
+
result.push(array.slice(i, i + chunkSize));
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
};
|