@scallop-io/sui-scallop-sdk 2.3.0-lst-x-oracle-alpha.9 → 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 -1783
- package/dist/index.d.ts +1811 -1783
- package/dist/index.js +49 -2
- package/dist/index.mjs +15 -2
- package/package.json +8 -7
- 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 -2
- 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 +99 -271
- 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 -33
- 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 -98
- 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 -18
- package/src/builders/oracles/oraclePackageRegistry.ts +0 -336
- package/src/builders/oracles/priceFeedUpdater.ts +0 -112
- package/src/builders/oracles/priceUpdateRequester.ts +0 -50
- package/src/builders/oracles/xOracleUpdateStrategy.ts +0 -214
- package/src/builders/oracles/xOracleUpdater.ts +0 -153
- 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
|
@@ -7,16 +7,18 @@ import {
|
|
|
7
7
|
Transaction,
|
|
8
8
|
} from '@scallop-io/sui-kit';
|
|
9
9
|
import ScallopConstants, { ScallopConstantsParams } from './scallopConstants';
|
|
10
|
-
import {
|
|
10
|
+
import { CoinPrices, CoinWrappedType, PoolAddress } from 'src/types';
|
|
11
|
+
import { findClosestUnlockRound } from 'src/utils';
|
|
12
|
+
import {
|
|
13
|
+
MAX_LOCK_DURATION,
|
|
14
|
+
queryKeys,
|
|
15
|
+
UNLOCK_ROUND_DURATION,
|
|
16
|
+
} from 'src/constants';
|
|
11
17
|
import { PriceFeed, SuiPriceServiceConnection } from '@pythnetwork/pyth-sui-js';
|
|
12
18
|
import ScallopSuiKit, { ScallopSuiKitParams } from './scallopSuiKit';
|
|
13
19
|
import { SuiObjectData } from '@mysten/sui/dist/cjs/client';
|
|
14
|
-
import { queryObligation } from 'src/queries
|
|
20
|
+
import { queryObligation } from 'src/queries';
|
|
15
21
|
import { ScallopUtilsInterface } from './interface';
|
|
16
|
-
import { MAX_LOCK_DURATION, UNLOCK_ROUND_DURATION } from 'src/constants/vesca';
|
|
17
|
-
import { queryKeys } from 'src/constants/queryKeys';
|
|
18
|
-
import { CoinWrappedType, PoolAddress } from 'src/types/constant';
|
|
19
|
-
import { CoinPrices } from 'src/types/util';
|
|
20
22
|
|
|
21
23
|
export type ScallopUtilsParams = {
|
|
22
24
|
pythEndpoints?: string[];
|
|
@@ -29,6 +31,7 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
29
31
|
public pythEndpoints: string[];
|
|
30
32
|
public readonly scallopSuiKit: ScallopSuiKit;
|
|
31
33
|
public readonly constants: ScallopConstants;
|
|
34
|
+
public readonly timeout: number;
|
|
32
35
|
|
|
33
36
|
constructor(params: ScallopUtilsParams = {}) {
|
|
34
37
|
this.constants = params.scallopConstants ?? new ScallopConstants(params);
|
|
@@ -42,6 +45,8 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
42
45
|
this.pythEndpoints = params.pythEndpoints ?? [
|
|
43
46
|
'https://hermes.pyth.network',
|
|
44
47
|
];
|
|
48
|
+
|
|
49
|
+
this.timeout = params.axiosTimeout ?? 4000;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
get walletAddress() {
|
|
@@ -536,7 +541,7 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
536
541
|
|
|
537
542
|
const priceIds = priceIdPairs.map(([_, priceId]) => priceId);
|
|
538
543
|
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
539
|
-
timeout:
|
|
544
|
+
timeout: this.timeout,
|
|
540
545
|
});
|
|
541
546
|
|
|
542
547
|
try {
|
|
@@ -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'),
|