@scallop-io/sui-scallop-sdk 2.3.0-lst-x-oracle-alpha.8 → 2.3.0
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 +1811 -1750
- package/dist/index.d.ts +1811 -1750
- package/dist/index.js +49 -2
- package/dist/index.mjs +15 -2
- package/package.json +8 -5
- package/src/builders/borrowIncentiveBuilder.ts +4 -4
- package/src/builders/coreBuilder.ts +86 -59
- package/src/builders/index.ts +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +2 -2
- package/src/builders/oracles/index.ts +365 -114
- package/src/builders/oracles/pyth.ts +135 -0
- package/src/builders/referralBuilder.ts +4 -10
- package/src/builders/sCoinBuilder.ts +2 -6
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +5 -5
- package/src/constants/common.ts +3 -0
- package/src/constants/index.ts +1 -1
- package/src/constants/queryKeys.ts +1 -1
- package/src/constants/testAddress.ts +95 -183
- package/src/constants/xoracle.ts +2 -8
- package/src/index.ts +1 -1
- package/src/models/index.ts +1 -2
- package/src/models/interface.ts +6 -6
- package/src/models/rateLimiter.ts +55 -0
- package/src/models/scallop.ts +1 -1
- package/src/models/scallopAddress.ts +5 -25
- package/src/models/scallopBuilder.ts +14 -11
- package/src/models/scallopClient.ts +31 -14
- package/src/models/scallopConstants.ts +3 -3
- package/src/models/scallopIndexer.ts +3 -4
- package/src/models/scallopQuery.ts +112 -56
- package/src/models/scallopQueryClient.ts +1 -1
- package/src/models/scallopSuiKit.ts +1 -1
- package/src/models/scallopUtils.ts +12 -7
- package/src/queries/borrowIncentiveQuery.ts +4 -3
- package/src/queries/coreQuery.ts +114 -186
- package/src/queries/index.ts +3 -4
- package/src/queries/loyaltyProgramQuery.ts +2 -2
- package/src/queries/ownerQuery.ts +32 -0
- package/src/queries/poolAddressesQuery.ts +1 -3
- package/src/queries/portfolioQuery.ts +68 -16
- package/src/queries/priceQuery.ts +2 -3
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +57 -74
- package/src/queries/vescaQuery.ts +3 -3
- package/src/queries/xOracleQuery.ts +4 -21
- package/src/types/address.ts +47 -85
- package/src/types/builder/core.ts +40 -15
- package/src/types/builder/index.ts +17 -1
- package/src/types/constant/enum.ts +64 -0
- package/src/types/constant/index.ts +1 -2
- package/src/types/constant/xOracle.ts +7 -10
- package/src/types/index.ts +1 -1
- package/src/types/query/core.ts +3 -0
- package/src/types/query/index.ts +1 -0
- package/src/types/query/sCoin.ts +1 -0
- package/src/{builders/utils.ts → utils/builder.ts} +1 -1
- package/src/utils/core.ts +18 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/indexer.ts +47 -0
- package/src/{queries/utils.ts → utils/query.ts} +7 -25
- package/src/utils/util.ts +42 -0
- package/src/builders/oracles/error.ts +0 -29
- package/src/builders/oracles/oraclePackageRegistry.ts +0 -322
- package/src/builders/oracles/priceFeedUpdater.ts +0 -112
- package/src/builders/oracles/priceUpdateRequester.ts +0 -50
- package/src/builders/oracles/xOracleUpdateStrategy.ts +0 -178
- package/src/builders/oracles/xOracleUpdater.ts +0 -160
- package/src/constants/api.ts +0 -2
- package/src/models/utils.ts +0 -97
- package/src/types/builder/type.ts +0 -25
- package/src/types/constant/package.ts +0 -16
- /package/src/types/{util.ts → utils.ts} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
parseOriginBorrowIncentivePoolData,
|
|
4
4
|
parseOriginBorrowIncentiveAccountData,
|
|
5
5
|
calculateBorrowIncentivePoolPointData,
|
|
6
|
-
} from '
|
|
6
|
+
} from 'src/utils';
|
|
7
7
|
import type {
|
|
8
8
|
ScallopAddress,
|
|
9
9
|
ScallopQuery,
|
|
@@ -16,11 +16,12 @@ import type {
|
|
|
16
16
|
BorrowIncentiveAccountsQueryInterface,
|
|
17
17
|
BorrowIncentiveAccounts,
|
|
18
18
|
BorrowIncentivePoolPoints,
|
|
19
|
+
OptionalKeys,
|
|
20
|
+
CoinPrices,
|
|
19
21
|
MarketPools,
|
|
20
|
-
} from 'src/types
|
|
22
|
+
} from 'src/types';
|
|
21
23
|
import BigNumber from 'bignumber.js';
|
|
22
24
|
import { SuiObjectRef } from '@mysten/sui/client';
|
|
23
|
-
import { CoinPrices, OptionalKeys } from 'src/types/util';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Query borrow incentive pools data using moveCall
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
parseOriginMarketCollateralData,
|
|
6
6
|
calculateMarketCollateralData,
|
|
7
7
|
parseObjectAs,
|
|
8
|
-
|
|
8
|
+
partitionArray,
|
|
9
|
+
} from 'src/utils';
|
|
9
10
|
import type {
|
|
10
11
|
SuiObjectResponse,
|
|
11
12
|
SuiObjectData,
|
|
@@ -26,11 +27,13 @@ import {
|
|
|
26
27
|
BalanceSheet,
|
|
27
28
|
RiskModel,
|
|
28
29
|
CollateralStat,
|
|
30
|
+
OptionalKeys,
|
|
31
|
+
CoinPrices,
|
|
29
32
|
OriginMarketPoolData,
|
|
30
33
|
BorrowFee,
|
|
31
34
|
BorrowDynamic,
|
|
32
35
|
OriginMarketCollateralData,
|
|
33
|
-
} from 'src/types
|
|
36
|
+
} from 'src/types';
|
|
34
37
|
import BigNumber from 'bignumber.js';
|
|
35
38
|
import { getSupplyLimit } from './supplyLimitQuery';
|
|
36
39
|
import { isIsolatedAsset } from './isolatedAssetQuery';
|
|
@@ -43,7 +46,6 @@ import {
|
|
|
43
46
|
ScallopIndexer,
|
|
44
47
|
ScallopAddress,
|
|
45
48
|
} from 'src/models';
|
|
46
|
-
import { CoinPrices, OptionalKeys } from 'src/types/util';
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* Query market data.
|
|
@@ -125,25 +127,7 @@ export const queryMarket = async (
|
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
128
|
-
|
|
129
|
-
maxBorrowRate: pool.maxBorrowRate,
|
|
130
|
-
interestRate: pool.interestRate,
|
|
131
|
-
interestRateScale: pool.interestRateScale,
|
|
132
|
-
borrowIndex: pool.borrowIndex,
|
|
133
|
-
lastUpdated: pool.lastUpdated,
|
|
134
|
-
cash: pool.cash,
|
|
135
|
-
debt: pool.debt,
|
|
136
|
-
marketCoinSupply: pool.marketCoinSupply,
|
|
137
|
-
reserve: pool.reserve,
|
|
138
|
-
reserveFactor: pool.reserveFactor,
|
|
139
|
-
borrowWeight: pool.borrowWeight,
|
|
140
|
-
borrowFeeRate: pool.borrowFeeRate,
|
|
141
|
-
baseBorrowRatePerSec: pool.baseBorrowRatePerSec,
|
|
142
|
-
borrowRateOnHighKink: pool.borrowRateOnHighKink,
|
|
143
|
-
borrowRateOnMidKink: pool.borrowRateOnMidKink,
|
|
144
|
-
highKink: pool.highKink,
|
|
145
|
-
midKink: pool.midKink,
|
|
146
|
-
minBorrowAmount: pool.minBorrowAmount,
|
|
130
|
+
...pool,
|
|
147
131
|
isIsolated: await isIsolatedAsset(utils, poolCoinName),
|
|
148
132
|
supplyLimit: (await getSupplyLimit(utils, poolCoinName)) ?? '0',
|
|
149
133
|
borrowLimit: (await getBorrowLimit(utils, poolCoinName)) ?? '0',
|
|
@@ -157,19 +141,12 @@ export const queryMarket = async (
|
|
|
157
141
|
pools[poolCoinName] = {
|
|
158
142
|
coinName: poolCoinName,
|
|
159
143
|
symbol: utils.parseSymbol(poolCoinName),
|
|
160
|
-
coinType: coinType,
|
|
161
144
|
marketCoinType: utils.parseMarketCoinType(poolCoinName),
|
|
162
145
|
sCoinType:
|
|
163
146
|
utils.parseSCoinType(utils.parseMarketCoinName(poolCoinName)) ?? '',
|
|
164
147
|
coinWrappedType: utils.getCoinWrappedType(poolCoinName),
|
|
165
148
|
coinPrice: coinPrice,
|
|
166
|
-
|
|
167
|
-
midKink: parsedMarketPoolData.midKink,
|
|
168
|
-
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
169
|
-
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
170
|
-
borrowFee: parsedMarketPoolData.borrowFee,
|
|
171
|
-
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
172
|
-
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
149
|
+
...parsedMarketPoolData,
|
|
173
150
|
...calculatedMarketPoolData,
|
|
174
151
|
};
|
|
175
152
|
}
|
|
@@ -185,14 +162,8 @@ export const queryMarket = async (
|
|
|
185
162
|
}
|
|
186
163
|
|
|
187
164
|
const parsedMarketCollateralData = parseOriginMarketCollateralData({
|
|
188
|
-
|
|
189
|
-
collateralFactor: collateral.collateralFactor,
|
|
190
|
-
liquidationFactor: collateral.liquidationFactor,
|
|
191
|
-
liquidationDiscount: collateral.liquidationDiscount,
|
|
165
|
+
...collateral,
|
|
192
166
|
liquidationPenalty: collateral.liquidationPanelty,
|
|
193
|
-
liquidationReserveFactor: collateral.liquidationReserveFactor,
|
|
194
|
-
maxCollateralAmount: collateral.maxCollateralAmount,
|
|
195
|
-
totalCollateralAmount: collateral.totalCollateralAmount,
|
|
196
167
|
isIsolated: await isIsolatedAsset(utils, collateralCoinName),
|
|
197
168
|
});
|
|
198
169
|
|
|
@@ -204,17 +175,10 @@ export const queryMarket = async (
|
|
|
204
175
|
collaterals[collateralCoinName] = {
|
|
205
176
|
coinName: collateralCoinName,
|
|
206
177
|
symbol: utils.parseSymbol(collateralCoinName),
|
|
207
|
-
coinType: coinType,
|
|
208
178
|
marketCoinType: utils.parseMarketCoinType(collateralCoinName),
|
|
209
179
|
coinWrappedType: utils.getCoinWrappedType(collateralCoinName),
|
|
210
180
|
coinPrice: coinPrice,
|
|
211
|
-
|
|
212
|
-
liquidationFactor: parsedMarketCollateralData.liquidationFactor,
|
|
213
|
-
liquidationDiscount: parsedMarketCollateralData.liquidationDiscount,
|
|
214
|
-
liquidationPenalty: parsedMarketCollateralData.liquidationPenalty,
|
|
215
|
-
liquidationReserveFactor:
|
|
216
|
-
parsedMarketCollateralData.liquidationReserveFactor,
|
|
217
|
-
|
|
181
|
+
...parsedMarketCollateralData,
|
|
218
182
|
...calculatedMarketCollateralData,
|
|
219
183
|
};
|
|
220
184
|
}
|
|
@@ -236,130 +200,84 @@ const queryRequiredMarketObjects = async (
|
|
|
236
200
|
},
|
|
237
201
|
poolCoinNames: string[]
|
|
238
202
|
) => {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
collateralStat: [],
|
|
255
|
-
borrowDynamic: [],
|
|
256
|
-
interestModel: [],
|
|
257
|
-
riskModel: [],
|
|
258
|
-
borrowFeeKey: [],
|
|
259
|
-
supplyLimitKey: [],
|
|
260
|
-
borrowLimitKey: [],
|
|
261
|
-
isolatedAssetKey: [],
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
const taskMap = new Map<string, KeyType>();
|
|
265
|
-
|
|
266
|
-
// Single iteration to collect all keys and map tasks
|
|
203
|
+
const keyTypes = [
|
|
204
|
+
'lendingPoolAddress',
|
|
205
|
+
'collateralPoolAddress',
|
|
206
|
+
'borrowDynamic',
|
|
207
|
+
'interestModel',
|
|
208
|
+
'riskModel',
|
|
209
|
+
'borrowFeeKey',
|
|
210
|
+
'supplyLimitKey',
|
|
211
|
+
'borrowLimitKey',
|
|
212
|
+
'isolatedAssetKey',
|
|
213
|
+
] as const;
|
|
214
|
+
|
|
215
|
+
const allObjectIds: string[] = [];
|
|
216
|
+
|
|
217
|
+
// Get all object ids
|
|
267
218
|
for (const poolCoinName of poolCoinNames) {
|
|
268
219
|
const poolData = utils.constants.poolAddresses[poolCoinName];
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
borrowDynamic: poolData?.borrowDynamic,
|
|
273
|
-
interestModel: poolData?.interestModel,
|
|
274
|
-
riskModel: poolData?.riskModel,
|
|
275
|
-
borrowFeeKey: poolData?.borrowFeeKey,
|
|
276
|
-
supplyLimitKey: poolData?.supplyLimitKey,
|
|
277
|
-
borrowLimitKey: poolData?.borrowLimitKey,
|
|
278
|
-
isolatedAssetKey: poolData?.isolatedAssetKey,
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
// Add to key collections
|
|
282
|
-
(Object.entries(task) as [keyof KeyType, string | undefined][]).forEach(
|
|
283
|
-
([key, value]) => {
|
|
284
|
-
if (value) keyCollections[key].push(value);
|
|
220
|
+
for (const keyType of keyTypes) {
|
|
221
|
+
if (poolData?.[keyType] && poolData[keyType] !== '') {
|
|
222
|
+
allObjectIds.push(poolData[keyType]);
|
|
285
223
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
taskMap.set(poolCoinName, task);
|
|
224
|
+
}
|
|
289
225
|
}
|
|
290
226
|
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
scallopSuiKit.queryGetObjects(keyCollections.collateralStat, options),
|
|
298
|
-
scallopSuiKit.queryGetObjects(keyCollections.borrowDynamic, options),
|
|
299
|
-
scallopSuiKit.queryGetObjects(keyCollections.interestModel, options),
|
|
300
|
-
scallopSuiKit.queryGetObjects(keyCollections.riskModel, options),
|
|
301
|
-
scallopSuiKit.queryGetObjects(keyCollections.borrowFeeKey, options),
|
|
302
|
-
scallopSuiKit.queryGetObjects(keyCollections.supplyLimitKey, options),
|
|
303
|
-
scallopSuiKit.queryGetObjects(keyCollections.borrowLimitKey, options),
|
|
304
|
-
]);
|
|
305
|
-
|
|
306
|
-
// Phase 3: Single-pass result mapping
|
|
307
|
-
const resultMaps = {
|
|
308
|
-
balanceSheet: new Map<string, SuiObjectData>(),
|
|
309
|
-
collateralStat: new Map<string, SuiObjectData>(),
|
|
310
|
-
borrowDynamic: new Map<string, SuiObjectData>(),
|
|
311
|
-
interestModel: new Map<string, SuiObjectData>(),
|
|
312
|
-
riskModel: new Map<string, SuiObjectData>(),
|
|
313
|
-
borrowFeeKey: new Map<string, SuiObjectData>(),
|
|
314
|
-
supplyLimitKey: new Map<string, SuiObjectData>(),
|
|
315
|
-
borrowLimitKey: new Map<string, SuiObjectData>(),
|
|
316
|
-
isolatedAssetKey: new Map<string, SuiObjectData>(),
|
|
317
|
-
isIsolated: new Map<string, boolean>(),
|
|
318
|
-
} as Record<keyof KeyType, Map<string, SuiObjectData>>;
|
|
319
|
-
|
|
320
|
-
queryResults.forEach((objects, index) => {
|
|
321
|
-
const keyType = Object.keys(resultMaps)[index] as keyof KeyType;
|
|
322
|
-
objects.forEach((obj) => {
|
|
323
|
-
resultMaps[keyType].set(obj.objectId, obj);
|
|
227
|
+
const objectDatas: SuiObjectData[] = [];
|
|
228
|
+
const batches = partitionArray(allObjectIds, 50);
|
|
229
|
+
|
|
230
|
+
for (const batch of batches) {
|
|
231
|
+
const responses = await scallopSuiKit.queryGetObjects(batch, {
|
|
232
|
+
showContent: true,
|
|
324
233
|
});
|
|
325
|
-
|
|
234
|
+
if (responses.length > 0) {
|
|
235
|
+
objectDatas.push(...responses);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Transform into map
|
|
240
|
+
const objectDataMap = objectDatas.reduce(
|
|
241
|
+
(acc, obj) => {
|
|
242
|
+
acc[obj.objectId] = obj;
|
|
243
|
+
return acc;
|
|
244
|
+
},
|
|
245
|
+
{} as Record<string, SuiObjectData>
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const _resultKeys = [
|
|
249
|
+
'balanceSheet',
|
|
250
|
+
'collateralStat',
|
|
251
|
+
'borrowDynamic',
|
|
252
|
+
'interestModel',
|
|
253
|
+
'riskModel',
|
|
254
|
+
'borrowFeeKey',
|
|
255
|
+
'supplyLimitKey',
|
|
256
|
+
'borrowLimitKey',
|
|
257
|
+
'isolatedAssetKey',
|
|
258
|
+
] as const;
|
|
259
|
+
|
|
260
|
+
const results: Record<
|
|
261
|
+
string,
|
|
262
|
+
Record<(typeof _resultKeys)[number], SuiObjectData>
|
|
263
|
+
> = {};
|
|
326
264
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
: undefined,
|
|
340
|
-
interestModel: task.interestModel
|
|
341
|
-
? resultMaps.interestModel.get(task.interestModel)
|
|
342
|
-
: undefined,
|
|
343
|
-
riskModel: task.riskModel
|
|
344
|
-
? resultMaps.riskModel.get(task.riskModel)
|
|
345
|
-
: undefined,
|
|
346
|
-
borrowFeeKey: task.borrowFeeKey
|
|
347
|
-
? resultMaps.borrowFeeKey.get(task.borrowFeeKey)
|
|
348
|
-
: undefined,
|
|
349
|
-
supplyLimitKey: task.supplyLimitKey
|
|
350
|
-
? resultMaps.supplyLimitKey.get(task.supplyLimitKey)
|
|
351
|
-
: undefined,
|
|
352
|
-
borrowLimitKey: task.borrowLimitKey
|
|
353
|
-
? resultMaps.borrowLimitKey.get(task.borrowLimitKey)
|
|
354
|
-
: undefined,
|
|
355
|
-
isolatedAssetKey: task.isolatedAssetKey
|
|
356
|
-
? resultMaps.isolatedAssetKey.get(task.isolatedAssetKey)
|
|
357
|
-
: undefined,
|
|
358
|
-
isIsolated: utils.constants.poolAddresses[poolCoinName]?.isIsolated,
|
|
265
|
+
for (const poolCoinName of poolCoinNames) {
|
|
266
|
+
const poolData = utils.constants.poolAddresses[poolCoinName];
|
|
267
|
+
results[poolCoinName] = {
|
|
268
|
+
balanceSheet: objectDataMap[poolData?.lendingPoolAddress ?? ''],
|
|
269
|
+
collateralStat: objectDataMap[poolData?.collateralPoolAddress ?? ''],
|
|
270
|
+
borrowDynamic: objectDataMap[poolData?.borrowDynamic ?? ''],
|
|
271
|
+
interestModel: objectDataMap[poolData?.interestModel ?? ''],
|
|
272
|
+
riskModel: objectDataMap[poolData?.riskModel ?? ''],
|
|
273
|
+
borrowFeeKey: objectDataMap[poolData?.borrowFeeKey ?? ''],
|
|
274
|
+
supplyLimitKey: objectDataMap[poolData?.supplyLimitKey ?? ''],
|
|
275
|
+
borrowLimitKey: objectDataMap[poolData?.borrowLimitKey ?? ''],
|
|
276
|
+
isolatedAssetKey: objectDataMap[poolData?.isolatedAssetKey ?? ''],
|
|
359
277
|
};
|
|
360
278
|
}
|
|
361
279
|
|
|
362
|
-
return
|
|
280
|
+
return results;
|
|
363
281
|
};
|
|
364
282
|
|
|
365
283
|
/**
|
|
@@ -449,29 +367,32 @@ export const getMarketPools = async (
|
|
|
449
367
|
};
|
|
450
368
|
};
|
|
451
369
|
|
|
452
|
-
const parseMarketPoolObjects = (
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
|
|
370
|
+
const parseMarketPoolObjects = async (
|
|
371
|
+
utils: ScallopUtils,
|
|
372
|
+
{
|
|
373
|
+
balanceSheet,
|
|
374
|
+
borrowDynamic,
|
|
375
|
+
collateralStat,
|
|
376
|
+
interestModel,
|
|
377
|
+
riskModel,
|
|
378
|
+
borrowFeeKey,
|
|
379
|
+
supplyLimitKey,
|
|
380
|
+
borrowLimitKey,
|
|
381
|
+
}: {
|
|
382
|
+
balanceSheet?: SuiObjectData;
|
|
383
|
+
borrowDynamic?: SuiObjectData;
|
|
384
|
+
collateralStat?: SuiObjectData;
|
|
385
|
+
interestModel?: SuiObjectData;
|
|
386
|
+
riskModel?: SuiObjectData;
|
|
387
|
+
borrowFeeKey?: SuiObjectData;
|
|
388
|
+
supplyLimitKey?: SuiObjectData;
|
|
389
|
+
borrowLimitKey?: SuiObjectData;
|
|
390
|
+
}
|
|
391
|
+
): Promise<
|
|
392
|
+
OriginMarketPoolData & {
|
|
393
|
+
parsedOriginMarketCollateral?: OriginMarketCollateralData;
|
|
394
|
+
}
|
|
395
|
+
> => {
|
|
475
396
|
if (!balanceSheet || !borrowDynamic || !interestModel) {
|
|
476
397
|
throw new Error('Missing required market objects');
|
|
477
398
|
}
|
|
@@ -494,11 +415,15 @@ const parseMarketPoolObjects = ({
|
|
|
494
415
|
? parseObjectAs<CollateralStat>(collateralStat)
|
|
495
416
|
: undefined;
|
|
496
417
|
|
|
418
|
+
const isIsolated = await isIsolatedAsset(
|
|
419
|
+
utils,
|
|
420
|
+
utils.parseCoinNameFromType(`0x${_interestModel.type.fields.name}`)
|
|
421
|
+
);
|
|
422
|
+
|
|
497
423
|
const parsedOriginMarketCollateral =
|
|
498
424
|
_riskModel && _collateralStat
|
|
499
425
|
? {
|
|
500
426
|
type: _interestModel.type.fields,
|
|
501
|
-
isIsolated: isIsolated,
|
|
502
427
|
collateralFactor: _riskModel.collateral_factor.fields,
|
|
503
428
|
liquidationFactor: _riskModel.liquidation_factor.fields,
|
|
504
429
|
liquidationPenalty: _riskModel.liquidation_penalty.fields,
|
|
@@ -507,6 +432,7 @@ const parseMarketPoolObjects = ({
|
|
|
507
432
|
_riskModel.liquidation_revenue_factor.fields,
|
|
508
433
|
maxCollateralAmount: _riskModel.max_collateral_amount,
|
|
509
434
|
totalCollateralAmount: _collateralStat.amount,
|
|
435
|
+
isIsolated,
|
|
510
436
|
}
|
|
511
437
|
: undefined;
|
|
512
438
|
|
|
@@ -530,9 +456,9 @@ const parseMarketPoolObjects = ({
|
|
|
530
456
|
highKink: _interestModel.high_kink.fields,
|
|
531
457
|
midKink: _interestModel.mid_kink.fields,
|
|
532
458
|
minBorrowAmount: _interestModel.min_borrow_amount,
|
|
533
|
-
isIsolated,
|
|
534
459
|
supplyLimit: _supplyLimit,
|
|
535
460
|
borrowLimit: _borrowLimit,
|
|
461
|
+
isIsolated,
|
|
536
462
|
parsedOriginMarketCollateral,
|
|
537
463
|
};
|
|
538
464
|
};
|
|
@@ -560,7 +486,6 @@ export const getMarketPool = async (
|
|
|
560
486
|
supplyLimitKey: SuiObjectData;
|
|
561
487
|
borrowLimitKey: SuiObjectData;
|
|
562
488
|
isolatedAssetKey?: SuiObjectData;
|
|
563
|
-
isIsolated: boolean;
|
|
564
489
|
}
|
|
565
490
|
): Promise<
|
|
566
491
|
{ marketPool: MarketPool; collateral?: MarketCollateral } | undefined
|
|
@@ -603,7 +528,10 @@ export const getMarketPool = async (
|
|
|
603
528
|
throw new Error(
|
|
604
529
|
`Failed to fetch required market objects for ${poolCoinName}`
|
|
605
530
|
);
|
|
606
|
-
const parsedMarketPoolObjects = parseMarketPoolObjects(
|
|
531
|
+
const parsedMarketPoolObjects = await parseMarketPoolObjects(
|
|
532
|
+
query.utils,
|
|
533
|
+
requiredObjects
|
|
534
|
+
);
|
|
607
535
|
const parsedMarketPoolData = parseOriginMarketPoolData(
|
|
608
536
|
parsedMarketPoolObjects
|
|
609
537
|
);
|
package/src/queries/index.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
export * from './borrowIncentiveQuery';
|
|
2
|
-
export * from './borrowLimitQuery';
|
|
3
2
|
export * from './coreQuery';
|
|
4
|
-
export * from './flashloanFeeQuery';
|
|
5
3
|
export * from './isolatedAssetQuery';
|
|
6
4
|
export * from './loyaltyProgramQuery';
|
|
7
|
-
export * from './poolAddressesQuery';
|
|
8
5
|
export * from './portfolioQuery';
|
|
9
6
|
export * from './priceQuery';
|
|
10
7
|
export * from './referralQuery';
|
|
11
8
|
export * from './sCoinQuery';
|
|
12
9
|
export * from './spoolQuery';
|
|
13
10
|
export * from './supplyLimitQuery';
|
|
14
|
-
export * from './switchboardQuery';
|
|
15
11
|
export * from './vescaQuery';
|
|
12
|
+
export * from './borrowLimitQuery';
|
|
13
|
+
export * from './poolAddressesQuery';
|
|
14
|
+
export * from './switchboardQuery';
|
|
16
15
|
export * from './xOracleQuery';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { MAX_LOCK_DURATION } from 'src/constants
|
|
3
|
+
import { MAX_LOCK_DURATION } from 'src/constants';
|
|
4
4
|
import { ScallopQuery } from 'src/models';
|
|
5
|
-
import { LoyaltyProgramInfo, VeScaLoyaltyProgramInfo } from 'src/types
|
|
5
|
+
import { LoyaltyProgramInfo, VeScaLoyaltyProgramInfo } from 'src/types';
|
|
6
6
|
import { z as zod } from 'zod';
|
|
7
7
|
|
|
8
8
|
const rewardPoolFieldsZod = zod
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// import { ObjectOwner, SuiObjectData } from '@mysten/sui/client';
|
|
2
|
+
|
|
3
|
+
// const parseOwnerAddress = (owner: ObjectOwner | null | undefined): string => {
|
|
4
|
+
// const notSupportedOwner =
|
|
5
|
+
// !owner ||
|
|
6
|
+
// typeof owner === 'string' ||
|
|
7
|
+
// (typeof owner === 'object' &&
|
|
8
|
+
// ('Shared' in owner || 'ConsensusV2' in owner));
|
|
9
|
+
// if (notSupportedOwner)
|
|
10
|
+
// throw new Error('Owner not supported (ConsensusV2 or Shared or Immutable)');
|
|
11
|
+
|
|
12
|
+
// if ('AddressOwner' in owner) {
|
|
13
|
+
// return owner.AddressOwner;
|
|
14
|
+
// } else {
|
|
15
|
+
// return owner.ObjectOwner;
|
|
16
|
+
// }
|
|
17
|
+
// };
|
|
18
|
+
|
|
19
|
+
// export const getObjectOwner = async (
|
|
20
|
+
// cache: ScallopCache,
|
|
21
|
+
// object: string | SuiObjectData
|
|
22
|
+
// ) => {
|
|
23
|
+
// if (typeof object === 'object') {
|
|
24
|
+
// return parseOwnerAddress(object.owner);
|
|
25
|
+
// }
|
|
26
|
+
|
|
27
|
+
// const objResponse = await cache.queryGetObject(object, {
|
|
28
|
+
// showOwner: true,
|
|
29
|
+
// });
|
|
30
|
+
|
|
31
|
+
// return parseOwnerAddress(objResponse.data?.owner);
|
|
32
|
+
// };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { getFullnodeUrl, SuiClient, SuiParsedData } from '@mysten/sui/client';
|
|
2
|
-
import { AddressesInterface } from 'src/types
|
|
3
|
-
import { PoolAddress } from 'src/types/constant';
|
|
4
|
-
import { OptionalKeys } from 'src/types/util';
|
|
2
|
+
import { AddressesInterface, OptionalKeys, PoolAddress } from 'src/types';
|
|
5
3
|
|
|
6
4
|
const RPC_PROVIDERS = [
|
|
7
5
|
getFullnodeUrl('mainnet'),
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { minBigNumber, estimatedFactor } from '
|
|
2
|
+
import { minBigNumber, estimatedFactor } from 'src/utils';
|
|
3
3
|
import type { ScallopQuery } from 'src/models';
|
|
4
|
-
import {
|
|
5
|
-
import { normalizeStructTag, SUI_TYPE_ARG } from '@scallop-io/sui-kit';
|
|
6
|
-
import {
|
|
7
|
-
CoinAmounts,
|
|
8
|
-
Lending,
|
|
9
|
-
Lendings,
|
|
4
|
+
import type {
|
|
10
5
|
Market,
|
|
11
|
-
MarketCollaterals,
|
|
12
6
|
MarketPool,
|
|
13
|
-
MarketPools,
|
|
14
|
-
ObligationAccount,
|
|
15
|
-
ObligationAccounts,
|
|
16
|
-
ObligationBorrowIncentiveReward,
|
|
17
7
|
Spool,
|
|
18
8
|
StakeAccount,
|
|
9
|
+
Lendings,
|
|
10
|
+
Lending,
|
|
11
|
+
ObligationAccounts,
|
|
12
|
+
ObligationAccount,
|
|
13
|
+
CoinAmounts,
|
|
14
|
+
CoinPrices,
|
|
19
15
|
TotalValueLocked,
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
ObligationBorrowIncentiveReward,
|
|
17
|
+
MarketPools,
|
|
18
|
+
MarketCollaterals,
|
|
19
|
+
} from 'src/types';
|
|
20
|
+
import { SuiObjectRef } from '@mysten/sui/client';
|
|
21
|
+
import { normalizeStructTag, SUI_TYPE_ARG } from '@scallop-io/sui-kit';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Get user lending infomation for specific pools.
|
|
@@ -293,6 +293,8 @@ export const getLending = async (
|
|
|
293
293
|
*
|
|
294
294
|
* @param query - The Scallop query instance.
|
|
295
295
|
* @param ownerAddress - The owner address.
|
|
296
|
+
* @param market - The market data.
|
|
297
|
+
* @param coinPrices - The coin prices data.
|
|
296
298
|
* @param indexer - Whether to use indexer.
|
|
297
299
|
* @return All obligation accounts data.
|
|
298
300
|
*/
|
|
@@ -338,12 +340,62 @@ export const getObligationAccounts = async (
|
|
|
338
340
|
return obligationAccounts;
|
|
339
341
|
};
|
|
340
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Get all obligation accounts data by ids.
|
|
345
|
+
*
|
|
346
|
+
* @param query - The Scallop query instance.
|
|
347
|
+
* @param obligationIds - Obligation account ids.
|
|
348
|
+
* @param market - The market data.
|
|
349
|
+
* @param coinPrices - The coin prices data.
|
|
350
|
+
* @param indexer - Whether to use indexer.
|
|
351
|
+
* @return All obligation accounts data.
|
|
352
|
+
*/
|
|
353
|
+
export const getObligationAccountsByIds = async (
|
|
354
|
+
query: ScallopQuery,
|
|
355
|
+
obligationIds: string[],
|
|
356
|
+
market?: {
|
|
357
|
+
pools: MarketPools;
|
|
358
|
+
collaterals: MarketCollaterals;
|
|
359
|
+
},
|
|
360
|
+
coinPrices?: CoinPrices,
|
|
361
|
+
indexer: boolean = false
|
|
362
|
+
) => {
|
|
363
|
+
market = market ?? (await query.getMarketPools(undefined, { indexer }));
|
|
364
|
+
coinPrices =
|
|
365
|
+
coinPrices ??
|
|
366
|
+
(await query.getAllCoinPrices({
|
|
367
|
+
marketPools: market.pools,
|
|
368
|
+
}));
|
|
369
|
+
|
|
370
|
+
const obligationAccounts: ObligationAccount[] = [];
|
|
371
|
+
await Promise.allSettled(
|
|
372
|
+
obligationIds.map(async (obligationId) => {
|
|
373
|
+
const obligationAccount = await getObligationAccount(
|
|
374
|
+
query,
|
|
375
|
+
obligationId,
|
|
376
|
+
'',
|
|
377
|
+
indexer,
|
|
378
|
+
market,
|
|
379
|
+
coinPrices,
|
|
380
|
+
{}
|
|
381
|
+
);
|
|
382
|
+
if (obligationAccount) obligationAccounts.push(obligationAccount);
|
|
383
|
+
})
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
return obligationAccounts;
|
|
387
|
+
};
|
|
388
|
+
|
|
341
389
|
/**
|
|
342
390
|
* Get obligation account data.
|
|
343
391
|
*
|
|
344
392
|
* @param query - The Scallop query instance.
|
|
345
393
|
* @param obligation - The obligation id.
|
|
394
|
+
* @param ownerAddress - The owner address of the obligation.
|
|
346
395
|
* @param indexer - Whether to use indexer.
|
|
396
|
+
* @param market - The market data.
|
|
397
|
+
* @param coinPrices - The coin prices data.
|
|
398
|
+
* @param coinAmounts - The coin amounts data.
|
|
347
399
|
* @return Obligation account data.
|
|
348
400
|
*/
|
|
349
401
|
export const getObligationAccount = async (
|
|
@@ -787,8 +839,6 @@ export const getTotalValueLocked = async (
|
|
|
787
839
|
query: ScallopQuery,
|
|
788
840
|
indexer: boolean = false
|
|
789
841
|
) => {
|
|
790
|
-
const market = await query.getMarketPools(undefined, { indexer });
|
|
791
|
-
|
|
792
842
|
let supplyLendingValue = BigNumber(0);
|
|
793
843
|
let supplyCollateralValue = BigNumber(0);
|
|
794
844
|
let borrowValue = BigNumber(0);
|
|
@@ -811,6 +861,8 @@ export const getTotalValueLocked = async (
|
|
|
811
861
|
return tvl;
|
|
812
862
|
}
|
|
813
863
|
|
|
864
|
+
const market = await query.getMarketPools(undefined, { indexer });
|
|
865
|
+
|
|
814
866
|
for (const pool of Object.values(market.pools)) {
|
|
815
867
|
if (!pool) continue;
|
|
816
868
|
supplyLendingValue = supplyLendingValue.plus(
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
2
|
import type { ScallopAddress, ScallopQuery, ScallopSuiKit } from 'src/models';
|
|
3
|
-
import type { MarketPools } from '
|
|
4
|
-
import type { CoinPrices } from 'src/types/util';
|
|
3
|
+
import type { CoinPrices, MarketPools, OptionalKeys } from '../types';
|
|
5
4
|
import BigNumber from 'bignumber.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -151,7 +150,7 @@ export const getAllCoinPrices = async (
|
|
|
151
150
|
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
152
151
|
}
|
|
153
152
|
|
|
154
|
-
const sCoinPrices:
|
|
153
|
+
const sCoinPrices: OptionalKeys<Record<string, number>> = {};
|
|
155
154
|
query.constants.whitelist.scoin.forEach((sCoinName) => {
|
|
156
155
|
const coinName = query.utils.parseCoinName(sCoinName);
|
|
157
156
|
sCoinPrices[sCoinName] = BigNumber(coinPrices[coinName] ?? 0)
|
|
@@ -2,7 +2,7 @@ import { bcs } from '@mysten/sui/bcs';
|
|
|
2
2
|
import assert from 'assert';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { ScallopQuery, ScallopUtils } from 'src/models';
|
|
5
|
-
import { OptionalKeys } from 'src/types
|
|
5
|
+
import { OptionalKeys, sCoinBalance } from 'src/types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Get total supply of sCoin
|
|
@@ -17,7 +17,7 @@ export const getSCoinTotalSupply = async (
|
|
|
17
17
|
utils: ScallopUtils;
|
|
18
18
|
},
|
|
19
19
|
sCoinName: string
|
|
20
|
-
): Promise<
|
|
20
|
+
): Promise<sCoinBalance> => {
|
|
21
21
|
const sCoinPkgId = utils.address.get('scoin.id');
|
|
22
22
|
// get treasury
|
|
23
23
|
const args = [utils.getSCoinTreasury(sCoinName)];
|