@scallop-io/sui-scallop-sdk 0.44.27 → 0.45.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/builders/borrowIncentiveBuilder.d.ts +0 -7
- package/dist/constants/cache.d.ts +8 -0
- package/dist/index.js +538 -268
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +522 -253
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.ts +1 -0
- package/dist/models/scallop.d.ts +7 -1
- package/dist/models/scallopAddress.d.ts +4 -2
- package/dist/models/scallopBuilder.d.ts +2 -0
- package/dist/models/scallopCache.d.ts +71 -0
- package/dist/models/scallopClient.d.ts +2 -0
- package/dist/models/scallopIndexer.d.ts +5 -3
- package/dist/models/scallopQuery.d.ts +14 -0
- package/dist/models/scallopUtils.d.ts +1 -0
- package/dist/queries/borrowIncentiveQuery.d.ts +8 -0
- package/dist/types/model.d.ts +2 -0
- package/dist/types/query/vesca.d.ts +2 -1
- package/package.json +2 -1
- package/src/builders/borrowIncentiveBuilder.ts +8 -57
- package/src/builders/vescaBuilder.ts +7 -3
- package/src/constants/cache.ts +15 -0
- package/src/models/index.ts +1 -0
- package/src/models/scallop.ts +26 -7
- package/src/models/scallopAddress.ts +24 -19
- package/src/models/scallopBuilder.ts +14 -4
- package/src/models/scallopCache.ts +245 -0
- package/src/models/scallopClient.ts +15 -4
- package/src/models/scallopIndexer.ts +58 -84
- package/src/models/scallopQuery.ts +34 -5
- package/src/models/scallopUtils.ts +53 -24
- package/src/queries/borrowIncentiveQuery.ts +99 -7
- package/src/queries/coreQuery.ts +62 -75
- package/src/queries/priceQuery.ts +4 -6
- package/src/queries/spoolQuery.ts +12 -15
- package/src/queries/vescaQuery.ts +20 -8
- package/src/types/model.ts +2 -0
- package/src/types/query/borrowIncentive.ts +0 -107
- package/src/types/query/vesca.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ __export(src_exports, {
|
|
|
53
53
|
Scallop: () => Scallop,
|
|
54
54
|
ScallopAddress: () => ScallopAddress,
|
|
55
55
|
ScallopBuilder: () => ScallopBuilder,
|
|
56
|
+
ScallopCache: () => ScallopCache,
|
|
56
57
|
ScallopClient: () => ScallopClient,
|
|
57
58
|
ScallopIndexer: () => ScallopIndexer,
|
|
58
59
|
ScallopQuery: () => ScallopQuery,
|
|
@@ -264,7 +265,198 @@ var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
|
264
265
|
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
265
266
|
|
|
266
267
|
// src/models/scallop.ts
|
|
267
|
-
var
|
|
268
|
+
var import_sui_kit10 = require("@scallop-io/sui-kit");
|
|
269
|
+
|
|
270
|
+
// src/models/scallopCache.ts
|
|
271
|
+
var import_query_core = require("@tanstack/query-core");
|
|
272
|
+
var import_sui_kit = require("@scallop-io/sui-kit");
|
|
273
|
+
|
|
274
|
+
// src/constants/cache.ts
|
|
275
|
+
var DEFAULT_CACHE_OPTIONS = {
|
|
276
|
+
defaultOptions: {
|
|
277
|
+
queries: {
|
|
278
|
+
staleTime: 3e3
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/models/scallopCache.ts
|
|
284
|
+
var ScallopCache = class {
|
|
285
|
+
constructor(cacheOptions, suiKit) {
|
|
286
|
+
this.queryClient = new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
287
|
+
this._suiKit = suiKit;
|
|
288
|
+
}
|
|
289
|
+
get suiKit() {
|
|
290
|
+
if (!this._suiKit) {
|
|
291
|
+
throw new Error("SuiKit instance is not initialized");
|
|
292
|
+
}
|
|
293
|
+
return this._suiKit;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* @description Invalidate cache based on the refetchType parameter
|
|
297
|
+
* @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
|
|
298
|
+
*
|
|
299
|
+
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
300
|
+
* - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
|
|
301
|
+
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
302
|
+
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
303
|
+
*/
|
|
304
|
+
invalidateAndRefetchAllCache(refetchType) {
|
|
305
|
+
return this.queryClient.invalidateQueries({
|
|
306
|
+
refetchType
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* @description Cache protocol config call for 60 seconds.
|
|
311
|
+
* @returns Promise<ProtocolConfig>
|
|
312
|
+
*/
|
|
313
|
+
async getProtocolConfig() {
|
|
314
|
+
return await this.queryClient.fetchQuery({
|
|
315
|
+
queryKey: ["getProtocolConfig"],
|
|
316
|
+
queryFn: async () => {
|
|
317
|
+
return await this.suiKit.client().getProtocolConfig();
|
|
318
|
+
},
|
|
319
|
+
staleTime: 3e4
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* @description Provides cache for inspectTxn of the SuiKit.
|
|
324
|
+
* @param QueryInspectTxnParams
|
|
325
|
+
* @param txBlock
|
|
326
|
+
* @returns Promise<DevInspectResults>
|
|
327
|
+
*/
|
|
328
|
+
async queryInspectTxn({
|
|
329
|
+
queryTarget,
|
|
330
|
+
args,
|
|
331
|
+
typeArgs
|
|
332
|
+
}) {
|
|
333
|
+
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
334
|
+
const resolvedArgs = await Promise.all(
|
|
335
|
+
args.map(async (arg) => {
|
|
336
|
+
if (typeof arg === "string") {
|
|
337
|
+
return (await this.queryGetObject(arg, { showContent: true })).data;
|
|
338
|
+
}
|
|
339
|
+
return arg;
|
|
340
|
+
})
|
|
341
|
+
);
|
|
342
|
+
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
343
|
+
const txBytes = await txBlock.txBlock.build({
|
|
344
|
+
client: this.suiKit.client(),
|
|
345
|
+
onlyTransactionKind: true,
|
|
346
|
+
protocolConfig: await this.getProtocolConfig()
|
|
347
|
+
});
|
|
348
|
+
const query = await this.queryClient.fetchQuery({
|
|
349
|
+
queryKey: typeArgs ? ["inspectTxn", queryTarget, JSON.stringify(args)] : [
|
|
350
|
+
"inspectTxn",
|
|
351
|
+
queryTarget,
|
|
352
|
+
JSON.stringify(args),
|
|
353
|
+
JSON.stringify(typeArgs)
|
|
354
|
+
],
|
|
355
|
+
queryFn: async () => {
|
|
356
|
+
return await this.suiKit.inspectTxn(txBytes);
|
|
357
|
+
},
|
|
358
|
+
staleTime: 8e3
|
|
359
|
+
// make stale time longer for inspectTxn results
|
|
360
|
+
});
|
|
361
|
+
return query;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* @description Provides cache for getObject of the SuiKit.
|
|
365
|
+
* @param objectId
|
|
366
|
+
* @param QueryObjectParams
|
|
367
|
+
* @returns Promise<SuiObjectResponse>
|
|
368
|
+
*/
|
|
369
|
+
async queryGetObject(objectId, options) {
|
|
370
|
+
const queryKey = ["getObject", objectId, this.suiKit.currentAddress()];
|
|
371
|
+
if (options) {
|
|
372
|
+
queryKey.push(JSON.stringify(options));
|
|
373
|
+
}
|
|
374
|
+
return this.queryClient.fetchQuery({
|
|
375
|
+
queryKey,
|
|
376
|
+
queryFn: async () => {
|
|
377
|
+
return await this.suiKit.client().getObject({
|
|
378
|
+
id: objectId,
|
|
379
|
+
options
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* @description Provides cache for getObjects of the SuiKit.
|
|
386
|
+
* @param objectIds
|
|
387
|
+
* @returns Promise<SuiObjectData[]>
|
|
388
|
+
*/
|
|
389
|
+
async queryGetObjects(objectIds, options) {
|
|
390
|
+
const queryKey = [
|
|
391
|
+
"getObjects",
|
|
392
|
+
JSON.stringify(objectIds),
|
|
393
|
+
this.suiKit.currentAddress()
|
|
394
|
+
];
|
|
395
|
+
return this.queryClient.fetchQuery({
|
|
396
|
+
queryKey,
|
|
397
|
+
queryFn: async () => {
|
|
398
|
+
return await this.suiKit.getObjects(objectIds, options);
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* @description Provides cache for getOwnedObjects of the SuiKit.
|
|
404
|
+
* @param input
|
|
405
|
+
* @returns Promise<PaginatedObjectsResponse>
|
|
406
|
+
*/
|
|
407
|
+
async queryGetOwnedObjects(input) {
|
|
408
|
+
const queryKey = ["getOwnedObjects", input.owner];
|
|
409
|
+
if (input.cursor) {
|
|
410
|
+
queryKey.push(JSON.stringify(input.cursor));
|
|
411
|
+
}
|
|
412
|
+
if (input.options) {
|
|
413
|
+
queryKey.push(JSON.stringify(input.options));
|
|
414
|
+
}
|
|
415
|
+
if (input.filter) {
|
|
416
|
+
queryKey.push(JSON.stringify(input.filter));
|
|
417
|
+
}
|
|
418
|
+
if (input.limit) {
|
|
419
|
+
queryKey.push(JSON.stringify(input.limit));
|
|
420
|
+
}
|
|
421
|
+
return this.queryClient.fetchQuery({
|
|
422
|
+
queryKey,
|
|
423
|
+
queryFn: async () => {
|
|
424
|
+
return await this.suiKit.client().getOwnedObjects(input);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
async queryGetDynamicFields(input) {
|
|
429
|
+
const queryKey = ["getDynamicFields", input.parentId];
|
|
430
|
+
if (input.cursor) {
|
|
431
|
+
queryKey.push(JSON.stringify(input.cursor));
|
|
432
|
+
}
|
|
433
|
+
if (input.cursor) {
|
|
434
|
+
queryKey.push(JSON.stringify(input.cursor));
|
|
435
|
+
}
|
|
436
|
+
if (input.limit) {
|
|
437
|
+
queryKey.push(JSON.stringify(input.limit));
|
|
438
|
+
}
|
|
439
|
+
return this.queryClient.fetchQuery({
|
|
440
|
+
queryKey,
|
|
441
|
+
queryFn: async () => {
|
|
442
|
+
return await this.suiKit.client().getDynamicFields(input);
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
async queryGetDynamicFieldObject(input) {
|
|
447
|
+
const queryKey = [
|
|
448
|
+
"getDynamicFieldObject",
|
|
449
|
+
input.parentId,
|
|
450
|
+
input.name.value
|
|
451
|
+
];
|
|
452
|
+
return this.queryClient.fetchQuery({
|
|
453
|
+
queryKey,
|
|
454
|
+
queryFn: async () => {
|
|
455
|
+
return await this.suiKit.client().getDynamicFieldObject(input);
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
};
|
|
268
460
|
|
|
269
461
|
// src/models/scallopAddress.ts
|
|
270
462
|
var import_axios = __toESM(require("axios"));
|
|
@@ -518,13 +710,9 @@ var EMPTY_ADDRESSES = {
|
|
|
518
710
|
}
|
|
519
711
|
};
|
|
520
712
|
var ScallopAddress = class {
|
|
521
|
-
constructor(params) {
|
|
713
|
+
constructor(params, cache) {
|
|
522
714
|
const { id, auth, network } = params;
|
|
523
|
-
|
|
524
|
-
this._auth = auth;
|
|
525
|
-
this._id = id;
|
|
526
|
-
this._network = network || "mainnet";
|
|
527
|
-
this._addressesMap = /* @__PURE__ */ new Map();
|
|
715
|
+
this._cache = cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS);
|
|
528
716
|
this._requestClient = import_axios.default.create({
|
|
529
717
|
baseURL: API_BASE_URL,
|
|
530
718
|
headers: {
|
|
@@ -533,6 +721,11 @@ var ScallopAddress = class {
|
|
|
533
721
|
},
|
|
534
722
|
timeout: 3e4
|
|
535
723
|
});
|
|
724
|
+
if (auth)
|
|
725
|
+
this._auth = auth;
|
|
726
|
+
this._id = id;
|
|
727
|
+
this._network = network || "mainnet";
|
|
728
|
+
this._addressesMap = /* @__PURE__ */ new Map();
|
|
536
729
|
}
|
|
537
730
|
/**
|
|
538
731
|
* Get addresses API id.
|
|
@@ -656,7 +849,7 @@ var ScallopAddress = class {
|
|
|
656
849
|
this._addressesMap.clear();
|
|
657
850
|
this.setAddresses(targetAddresses, targetNetwork);
|
|
658
851
|
const response = await this._requestClient.post(
|
|
659
|
-
|
|
852
|
+
`/addresses`,
|
|
660
853
|
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
661
854
|
{
|
|
662
855
|
headers: {
|
|
@@ -693,14 +886,16 @@ var ScallopAddress = class {
|
|
|
693
886
|
async read(id) {
|
|
694
887
|
const addressesId = id || this._id || void 0;
|
|
695
888
|
if (addressesId !== void 0) {
|
|
696
|
-
const response = await this.
|
|
697
|
-
|
|
698
|
-
{
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
889
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
890
|
+
queryKey: ["api-getAddresses", addressesId],
|
|
891
|
+
queryFn: async () => {
|
|
892
|
+
return await this._requestClient.get(`/addresses/${addressesId}`, {
|
|
893
|
+
headers: {
|
|
894
|
+
"Content-Type": "application/json"
|
|
895
|
+
}
|
|
896
|
+
});
|
|
702
897
|
}
|
|
703
|
-
);
|
|
898
|
+
});
|
|
704
899
|
if (response.status === 200) {
|
|
705
900
|
for (const [network, addresses] of Object.entries(
|
|
706
901
|
response.data
|
|
@@ -754,7 +949,7 @@ var ScallopAddress = class {
|
|
|
754
949
|
}
|
|
755
950
|
this.setAddresses(targetAddresses, targetNetwork);
|
|
756
951
|
const response = await this._requestClient.put(
|
|
757
|
-
|
|
952
|
+
`/addresses/${targetId}`,
|
|
758
953
|
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
759
954
|
{
|
|
760
955
|
headers: {
|
|
@@ -796,7 +991,7 @@ var ScallopAddress = class {
|
|
|
796
991
|
throw Error("Require specific addresses id to be deleted.");
|
|
797
992
|
if (apiKey !== void 0) {
|
|
798
993
|
const response = await this._requestClient.delete(
|
|
799
|
-
|
|
994
|
+
`/addresses/${targetId}`,
|
|
800
995
|
{
|
|
801
996
|
headers: {
|
|
802
997
|
"Content-Type": "application/json",
|
|
@@ -819,19 +1014,18 @@ var ScallopAddress = class {
|
|
|
819
1014
|
|
|
820
1015
|
// src/models/scallopClient.ts
|
|
821
1016
|
var import_utils20 = require("@mysten/sui.js/utils");
|
|
822
|
-
var
|
|
1017
|
+
var import_sui_kit9 = require("@scallop-io/sui-kit");
|
|
823
1018
|
|
|
824
1019
|
// src/models/scallopUtils.ts
|
|
825
1020
|
var import_utils9 = require("@mysten/sui.js/utils");
|
|
826
|
-
var
|
|
1021
|
+
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
827
1022
|
var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
|
|
828
1023
|
|
|
829
1024
|
// src/models/scallopQuery.ts
|
|
830
|
-
var
|
|
1025
|
+
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
831
1026
|
|
|
832
1027
|
// src/queries/coreQuery.ts
|
|
833
1028
|
var import_utils2 = require("@mysten/sui.js/utils");
|
|
834
|
-
var import_sui_kit = require("@scallop-io/sui-kit");
|
|
835
1029
|
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
836
1030
|
|
|
837
1031
|
// src/utils/builder.ts
|
|
@@ -1383,10 +1577,12 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
|
1383
1577
|
var queryMarket = async (query, indexer = false) => {
|
|
1384
1578
|
const packageId = query.address.get("core.packages.query.id");
|
|
1385
1579
|
const marketId = query.address.get("core.market");
|
|
1386
|
-
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
1387
1580
|
const queryTarget = `${packageId}::market_query::market_data`;
|
|
1388
|
-
|
|
1389
|
-
const queryResult = await query.
|
|
1581
|
+
const args = [marketId];
|
|
1582
|
+
const queryResult = await query.cache.queryInspectTxn(
|
|
1583
|
+
{ queryTarget, args }
|
|
1584
|
+
// txBlock
|
|
1585
|
+
);
|
|
1390
1586
|
const marketData = queryResult.events[0].parsedJson;
|
|
1391
1587
|
const coinPrices = await query.utils.getCoinPrices();
|
|
1392
1588
|
const pools = {};
|
|
@@ -1504,11 +1700,8 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
1504
1700
|
var getMarketPools = async (query, poolCoinNames, indexer = false) => {
|
|
1505
1701
|
poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
|
|
1506
1702
|
const marketId = query.address.get("core.market");
|
|
1507
|
-
const marketObjectResponse = await query.
|
|
1508
|
-
|
|
1509
|
-
options: {
|
|
1510
|
-
showContent: true
|
|
1511
|
-
}
|
|
1703
|
+
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
1704
|
+
showContent: true
|
|
1512
1705
|
});
|
|
1513
1706
|
const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
|
|
1514
1707
|
const marketPools = {};
|
|
@@ -1541,11 +1734,8 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
|
|
|
1541
1734
|
};
|
|
1542
1735
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
1543
1736
|
const marketId = query.address.get("core.market");
|
|
1544
|
-
marketObject = marketObject || (await query.
|
|
1545
|
-
|
|
1546
|
-
options: {
|
|
1547
|
-
showContent: true
|
|
1548
|
-
}
|
|
1737
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
1738
|
+
showContent: true
|
|
1549
1739
|
})).data;
|
|
1550
1740
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
1551
1741
|
let marketPool;
|
|
@@ -1566,7 +1756,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1566
1756
|
const fields = marketObject.content.fields;
|
|
1567
1757
|
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
1568
1758
|
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
1569
|
-
const balanceSheetDynamicFieldObjectResponse = await query.
|
|
1759
|
+
const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1570
1760
|
parentId: balanceSheetParentId,
|
|
1571
1761
|
name: {
|
|
1572
1762
|
type: "0x1::type_name::TypeName",
|
|
@@ -1581,7 +1771,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1581
1771
|
balanceSheet = dynamicFields.value.fields;
|
|
1582
1772
|
}
|
|
1583
1773
|
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
1584
|
-
const borrowIndexDynamicFieldObjectResponse = await query.
|
|
1774
|
+
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1585
1775
|
parentId: borrowIndexParentId,
|
|
1586
1776
|
name: {
|
|
1587
1777
|
type: "0x1::type_name::TypeName",
|
|
@@ -1596,7 +1786,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1596
1786
|
borrowIndex = dynamicFields.value.fields;
|
|
1597
1787
|
}
|
|
1598
1788
|
const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
|
|
1599
|
-
const interestModelDynamicFieldObjectResponse = await query.
|
|
1789
|
+
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1600
1790
|
parentId: interestModelParentId,
|
|
1601
1791
|
name: {
|
|
1602
1792
|
type: "0x1::type_name::TypeName",
|
|
@@ -1610,7 +1800,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1610
1800
|
const dynamicFields = interestModelDynamicFieldObject.content.fields;
|
|
1611
1801
|
interestModel = dynamicFields.value.fields;
|
|
1612
1802
|
}
|
|
1613
|
-
const borrowFeeDynamicFieldObjectResponse = await query.
|
|
1803
|
+
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1614
1804
|
parentId: marketId,
|
|
1615
1805
|
name: {
|
|
1616
1806
|
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
@@ -1677,11 +1867,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1677
1867
|
var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
|
|
1678
1868
|
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
1679
1869
|
const marketId = query.address.get("core.market");
|
|
1680
|
-
const marketObjectResponse = await query.
|
|
1681
|
-
|
|
1682
|
-
options: {
|
|
1683
|
-
showContent: true
|
|
1684
|
-
}
|
|
1870
|
+
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
1871
|
+
showContent: true
|
|
1685
1872
|
});
|
|
1686
1873
|
const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
|
|
1687
1874
|
const marketCollaterals = {};
|
|
@@ -1714,11 +1901,8 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
|
|
|
1714
1901
|
};
|
|
1715
1902
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
1716
1903
|
const marketId = query.address.get("core.market");
|
|
1717
|
-
marketObject = marketObject || (await query.
|
|
1718
|
-
|
|
1719
|
-
options: {
|
|
1720
|
-
showContent: true
|
|
1721
|
-
}
|
|
1904
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
1905
|
+
showContent: true
|
|
1722
1906
|
})).data;
|
|
1723
1907
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
1724
1908
|
let marketCollateral;
|
|
@@ -1737,7 +1921,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
1737
1921
|
const fields = marketObject.content.fields;
|
|
1738
1922
|
const coinType = query.utils.parseCoinType(collateralCoinName);
|
|
1739
1923
|
const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
|
|
1740
|
-
const riskModelDynamicFieldObjectResponse = await query.
|
|
1924
|
+
const riskModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1741
1925
|
parentId: riskModelParentId,
|
|
1742
1926
|
name: {
|
|
1743
1927
|
type: "0x1::type_name::TypeName",
|
|
@@ -1752,7 +1936,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
1752
1936
|
riskModel = dynamicFields.value.fields;
|
|
1753
1937
|
}
|
|
1754
1938
|
const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
|
|
1755
|
-
const collateralStatDynamicFieldObjectResponse = await query.
|
|
1939
|
+
const collateralStatDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1756
1940
|
parentId: collateralStatParentId,
|
|
1757
1941
|
name: {
|
|
1758
1942
|
type: "0x1::type_name::TypeName",
|
|
@@ -1808,7 +1992,7 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1808
1992
|
let hasNextPage = false;
|
|
1809
1993
|
let nextCursor = null;
|
|
1810
1994
|
do {
|
|
1811
|
-
const paginatedKeyObjectsResponse = await query.
|
|
1995
|
+
const paginatedKeyObjectsResponse = await query.cache.queryGetOwnedObjects({
|
|
1812
1996
|
owner,
|
|
1813
1997
|
filter: {
|
|
1814
1998
|
StructType: `${protocolObjectId}::obligation::ObligationKey`
|
|
@@ -1824,7 +2008,7 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1824
2008
|
}
|
|
1825
2009
|
} while (hasNextPage);
|
|
1826
2010
|
const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
|
|
1827
|
-
const keyObjects = await query.
|
|
2011
|
+
const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
|
|
1828
2012
|
const obligations = [];
|
|
1829
2013
|
for (const keyObject of keyObjects) {
|
|
1830
2014
|
const keyId = keyObject.objectId;
|
|
@@ -1838,12 +2022,10 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1838
2022
|
return obligations;
|
|
1839
2023
|
};
|
|
1840
2024
|
var getObligationLocked = async (query, obligationId) => {
|
|
1841
|
-
const obligationObjectResponse = await query.
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
}
|
|
1846
|
-
});
|
|
2025
|
+
const obligationObjectResponse = await query.cache.queryGetObject(
|
|
2026
|
+
obligationId,
|
|
2027
|
+
{ showContent: true }
|
|
2028
|
+
);
|
|
1847
2029
|
let obligationLocked = false;
|
|
1848
2030
|
if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
|
|
1849
2031
|
obligationLocked = Boolean(
|
|
@@ -1855,9 +2037,11 @@ var getObligationLocked = async (query, obligationId) => {
|
|
|
1855
2037
|
var queryObligation = async (query, obligationId) => {
|
|
1856
2038
|
const packageId = query.address.get("core.packages.query.id");
|
|
1857
2039
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
1858
|
-
const
|
|
1859
|
-
|
|
1860
|
-
|
|
2040
|
+
const args = [obligationId];
|
|
2041
|
+
const queryResult = await query.cache.queryInspectTxn(
|
|
2042
|
+
{ queryTarget, args }
|
|
2043
|
+
// txBlock
|
|
2044
|
+
);
|
|
1861
2045
|
return queryResult.events[0].parsedJson;
|
|
1862
2046
|
};
|
|
1863
2047
|
var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
|
|
@@ -1867,20 +2051,22 @@ var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
|
|
|
1867
2051
|
let hasNextPage = false;
|
|
1868
2052
|
let nextCursor = null;
|
|
1869
2053
|
do {
|
|
1870
|
-
const paginatedCoinObjectsResponse = await query.
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
2054
|
+
const paginatedCoinObjectsResponse = await query.cache.queryGetOwnedObjects(
|
|
2055
|
+
{
|
|
2056
|
+
owner,
|
|
2057
|
+
filter: {
|
|
2058
|
+
MatchAny: assetCoinNames.map((assetCoinName) => {
|
|
2059
|
+
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
2060
|
+
return { StructType: `0x2::coin::Coin<${coinType}>` };
|
|
2061
|
+
})
|
|
2062
|
+
},
|
|
2063
|
+
options: {
|
|
2064
|
+
showType: true,
|
|
2065
|
+
showContent: true
|
|
2066
|
+
},
|
|
2067
|
+
cursor: nextCursor
|
|
2068
|
+
}
|
|
2069
|
+
);
|
|
1884
2070
|
coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
|
|
1885
2071
|
if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
|
|
1886
2072
|
hasNextPage = true;
|
|
@@ -1914,14 +2100,16 @@ var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
|
|
|
1914
2100
|
let hasNextPage = false;
|
|
1915
2101
|
let nextCursor = null;
|
|
1916
2102
|
do {
|
|
1917
|
-
const paginatedCoinObjectsResponse = await query.
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
2103
|
+
const paginatedCoinObjectsResponse = await query.cache.queryGetOwnedObjects(
|
|
2104
|
+
{
|
|
2105
|
+
owner,
|
|
2106
|
+
filter: { StructType: `0x2::coin::Coin<${coinType}>` },
|
|
2107
|
+
options: {
|
|
2108
|
+
showContent: true
|
|
2109
|
+
},
|
|
2110
|
+
cursor: nextCursor
|
|
2111
|
+
}
|
|
2112
|
+
);
|
|
1925
2113
|
coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
|
|
1926
2114
|
if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
|
|
1927
2115
|
hasNextPage = true;
|
|
@@ -1953,7 +2141,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
|
1953
2141
|
let hasNextPage = false;
|
|
1954
2142
|
let nextCursor = null;
|
|
1955
2143
|
do {
|
|
1956
|
-
const paginatedMarketCoinObjectsResponse = await query.
|
|
2144
|
+
const paginatedMarketCoinObjectsResponse = await query.cache.queryGetOwnedObjects({
|
|
1957
2145
|
owner,
|
|
1958
2146
|
filter: {
|
|
1959
2147
|
MatchAny: marketCoinNames.map((marketCoinName) => {
|
|
@@ -2002,7 +2190,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
2002
2190
|
let hasNextPage = false;
|
|
2003
2191
|
let nextCursor = null;
|
|
2004
2192
|
do {
|
|
2005
|
-
const paginatedMarketCoinObjectsResponse = await query.
|
|
2193
|
+
const paginatedMarketCoinObjectsResponse = await query.cache.queryGetOwnedObjects({
|
|
2006
2194
|
owner,
|
|
2007
2195
|
filter: { StructType: `0x2::coin::Coin<${marketCoinType}>` },
|
|
2008
2196
|
options: {
|
|
@@ -2182,7 +2370,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2182
2370
|
let hasNextPage = false;
|
|
2183
2371
|
let nextCursor = null;
|
|
2184
2372
|
do {
|
|
2185
|
-
const paginatedStakeObjectsResponse = await query.
|
|
2373
|
+
const paginatedStakeObjectsResponse = await query.cache.queryGetOwnedObjects({
|
|
2186
2374
|
owner,
|
|
2187
2375
|
filter: { StructType: stakeAccountType },
|
|
2188
2376
|
options: {
|
|
@@ -2220,7 +2408,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2220
2408
|
{}
|
|
2221
2409
|
);
|
|
2222
2410
|
const stakeObjectIds = stakeObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
|
|
2223
|
-
const stakeObjects = await query.
|
|
2411
|
+
const stakeObjects = await query.cache.queryGetObjects(stakeObjectIds);
|
|
2224
2412
|
for (const stakeObject of stakeObjects) {
|
|
2225
2413
|
const id = stakeObject.objectId;
|
|
2226
2414
|
const type = stakeObject.type;
|
|
@@ -2328,12 +2516,9 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2328
2516
|
var getStakePool = async (query, marketCoinName) => {
|
|
2329
2517
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
2330
2518
|
let stakePool = void 0;
|
|
2331
|
-
const stakePoolObjectResponse = await query.
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
showContent: true,
|
|
2335
|
-
showType: true
|
|
2336
|
-
}
|
|
2519
|
+
const stakePoolObjectResponse = await query.cache.queryGetObject(poolId, {
|
|
2520
|
+
showContent: true,
|
|
2521
|
+
showType: true
|
|
2337
2522
|
});
|
|
2338
2523
|
if (stakePoolObjectResponse.data) {
|
|
2339
2524
|
const stakePoolObject = stakePoolObjectResponse.data;
|
|
@@ -2374,13 +2559,13 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2374
2559
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
2375
2560
|
);
|
|
2376
2561
|
let stakeRewardPool = void 0;
|
|
2377
|
-
const stakeRewardPoolObjectResponse = await query.
|
|
2378
|
-
|
|
2379
|
-
|
|
2562
|
+
const stakeRewardPoolObjectResponse = await query.cache.queryGetObject(
|
|
2563
|
+
poolId,
|
|
2564
|
+
{
|
|
2380
2565
|
showContent: true,
|
|
2381
2566
|
showType: true
|
|
2382
2567
|
}
|
|
2383
|
-
|
|
2568
|
+
);
|
|
2384
2569
|
if (stakeRewardPoolObjectResponse.data) {
|
|
2385
2570
|
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
2386
2571
|
const id = stakeRewardPoolObject.objectId;
|
|
@@ -2410,17 +2595,15 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2410
2595
|
|
|
2411
2596
|
// src/queries/borrowIncentiveQuery.ts
|
|
2412
2597
|
var import_utils6 = require("@mysten/sui.js/utils");
|
|
2413
|
-
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
2414
2598
|
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
|
|
2415
2599
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2416
2600
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2417
2601
|
];
|
|
2418
2602
|
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2419
2603
|
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2420
|
-
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
2421
2604
|
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2422
|
-
|
|
2423
|
-
const queryResult = await query.
|
|
2605
|
+
const args = [incentivePoolsId];
|
|
2606
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2424
2607
|
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2425
2608
|
const borrowIncentivePools = {};
|
|
2426
2609
|
if (indexer) {
|
|
@@ -2497,9 +2680,8 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
|
|
|
2497
2680
|
"borrowIncentive.incentiveAccounts"
|
|
2498
2681
|
);
|
|
2499
2682
|
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
2500
|
-
const
|
|
2501
|
-
|
|
2502
|
-
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2683
|
+
const args = [incentiveAccountsId, obligationId];
|
|
2684
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2503
2685
|
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
2504
2686
|
const borrowIncentiveAccounts = Object.values(
|
|
2505
2687
|
borrowIncentiveAccountsQueryData.pool_records
|
|
@@ -2514,18 +2696,73 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
|
|
|
2514
2696
|
}, {});
|
|
2515
2697
|
return borrowIncentiveAccounts;
|
|
2516
2698
|
};
|
|
2699
|
+
var getBindedObligationId = async (query, veScaKeyId) => {
|
|
2700
|
+
const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
|
|
2701
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2702
|
+
const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : query.address.get("vesca.id");
|
|
2703
|
+
const client = query.suiKit.client();
|
|
2704
|
+
const incentivePoolsResponse = await client.getObject({
|
|
2705
|
+
id: incentivePoolsId,
|
|
2706
|
+
options: {
|
|
2707
|
+
showContent: true
|
|
2708
|
+
}
|
|
2709
|
+
});
|
|
2710
|
+
if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
|
|
2711
|
+
return null;
|
|
2712
|
+
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
2713
|
+
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
2714
|
+
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
|
|
2715
|
+
const veScaBindTableResponse = await client.getDynamicFieldObject({
|
|
2716
|
+
parentId: veScaBindTableId,
|
|
2717
|
+
name: {
|
|
2718
|
+
type: keyType,
|
|
2719
|
+
value: veScaKeyId
|
|
2720
|
+
}
|
|
2721
|
+
});
|
|
2722
|
+
if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
|
|
2723
|
+
return null;
|
|
2724
|
+
const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
|
|
2725
|
+
const obligationId = veScaBindTableFields.value.fields.id;
|
|
2726
|
+
return obligationId;
|
|
2727
|
+
};
|
|
2728
|
+
var getBindedVeScaKey = async (query, obliationId) => {
|
|
2729
|
+
const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
|
|
2730
|
+
const incentiveAccountsId = query.address.get(
|
|
2731
|
+
"borrowIncentive.incentiveAccounts"
|
|
2732
|
+
);
|
|
2733
|
+
const corePkg = query.address.get("core.object");
|
|
2734
|
+
const client = query.suiKit.client();
|
|
2735
|
+
const incentiveAccountsObject = await client.getObject({
|
|
2736
|
+
id: incentiveAccountsId,
|
|
2737
|
+
options: {
|
|
2738
|
+
showContent: true
|
|
2739
|
+
}
|
|
2740
|
+
});
|
|
2741
|
+
if (incentiveAccountsObject.data?.content?.dataType !== "moveObject")
|
|
2742
|
+
return null;
|
|
2743
|
+
const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
|
|
2744
|
+
const bindedIncentiveAcc = await client.getDynamicFieldObject({
|
|
2745
|
+
parentId: incentiveAccountsTableId,
|
|
2746
|
+
name: {
|
|
2747
|
+
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|
|
2748
|
+
value: obliationId
|
|
2749
|
+
}
|
|
2750
|
+
});
|
|
2751
|
+
if (bindedIncentiveAcc.data?.content?.dataType !== "moveObject")
|
|
2752
|
+
return null;
|
|
2753
|
+
const bindedIncentiveAccFields = bindedIncentiveAcc.data.content.fields;
|
|
2754
|
+
return bindedIncentiveAccFields.value.fields.binded_ve_sca_key?.fields.id ?? null;
|
|
2755
|
+
};
|
|
2517
2756
|
|
|
2518
2757
|
// src/queries/priceQuery.ts
|
|
2519
2758
|
var getPythPrice = async (query, assetCoinName) => {
|
|
2520
2759
|
const pythFeedObjectId = query.address.get(
|
|
2521
2760
|
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
2522
2761
|
);
|
|
2523
|
-
const priceFeedObjectResponse = await query.
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
}
|
|
2528
|
-
});
|
|
2762
|
+
const priceFeedObjectResponse = await query.cache.queryGetObject(
|
|
2763
|
+
pythFeedObjectId,
|
|
2764
|
+
{ showContent: true }
|
|
2765
|
+
);
|
|
2529
2766
|
if (priceFeedObjectResponse.data) {
|
|
2530
2767
|
const priceFeedPoolObject = priceFeedObjectResponse.data;
|
|
2531
2768
|
if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
|
|
@@ -3089,7 +3326,7 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
|
3089
3326
|
const tableId = IS_VE_SCA_TEST ? "0xc607241e4a679fe376d1170b2fbe07b64917bfe69100d4825241cda20039d4bd" : query.address.get(`vesca.tableId`);
|
|
3090
3327
|
veScaKeyId = veScaKeyId || (await getVescaKeys(query, ownerAddress))[0].objectId;
|
|
3091
3328
|
let vesca = void 0;
|
|
3092
|
-
const veScaDynamicFieldObjectResponse = await query.
|
|
3329
|
+
const veScaDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3093
3330
|
parentId: tableId,
|
|
3094
3331
|
name: {
|
|
3095
3332
|
type: "0x2::object::ID",
|
|
@@ -3099,11 +3336,19 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
|
3099
3336
|
const veScaDynamicFieldObject = veScaDynamicFieldObjectResponse.data;
|
|
3100
3337
|
if (veScaDynamicFieldObject && veScaDynamicFieldObject.content && veScaDynamicFieldObject.content.dataType === "moveObject" && "fields" in veScaDynamicFieldObject.content) {
|
|
3101
3338
|
const dynamicFields = veScaDynamicFieldObject.content.fields.value.fields;
|
|
3339
|
+
const remainingLockPeriodInMilliseconds = Math.max(
|
|
3340
|
+
+dynamicFields.unlock_at * 1e3 - Date.now(),
|
|
3341
|
+
0
|
|
3342
|
+
);
|
|
3343
|
+
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
3344
|
+
const lockedScaCoin = (0, import_bignumber4.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
3345
|
+
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
3102
3346
|
vesca = {
|
|
3103
3347
|
id: veScaDynamicFieldObject.objectId,
|
|
3104
3348
|
keyId: veScaKeyId,
|
|
3105
|
-
lockedScaAmount
|
|
3106
|
-
lockedScaCoin
|
|
3349
|
+
lockedScaAmount,
|
|
3350
|
+
lockedScaCoin,
|
|
3351
|
+
currentVeScaBalance,
|
|
3107
3352
|
unlockAt: (0, import_bignumber4.default)(dynamicFields.unlock_at).toNumber()
|
|
3108
3353
|
};
|
|
3109
3354
|
}
|
|
@@ -3113,7 +3358,9 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
|
3113
3358
|
// src/models/scallopIndexer.ts
|
|
3114
3359
|
var import_axios2 = __toESM(require("axios"));
|
|
3115
3360
|
var ScallopIndexer = class {
|
|
3116
|
-
constructor() {
|
|
3361
|
+
constructor(params, instance) {
|
|
3362
|
+
this.params = params;
|
|
3363
|
+
this._cache = instance?.cache ?? new ScallopCache();
|
|
3117
3364
|
this._requestClient = import_axios2.default.create({
|
|
3118
3365
|
baseURL: SDK_API_BASE_URL,
|
|
3119
3366
|
headers: {
|
|
@@ -3129,7 +3376,12 @@ var ScallopIndexer = class {
|
|
|
3129
3376
|
* @return Market data.
|
|
3130
3377
|
*/
|
|
3131
3378
|
async getMarket() {
|
|
3132
|
-
const response = await this.
|
|
3379
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
3380
|
+
queryKey: ["market"],
|
|
3381
|
+
queryFn: async () => {
|
|
3382
|
+
return await this._requestClient.get(`/api/market`);
|
|
3383
|
+
}
|
|
3384
|
+
});
|
|
3133
3385
|
if (response.status === 200) {
|
|
3134
3386
|
return {
|
|
3135
3387
|
pools: response.data.pools.reduce((marketPools, marketPool) => {
|
|
@@ -3154,15 +3406,8 @@ var ScallopIndexer = class {
|
|
|
3154
3406
|
* @return Market pools data.
|
|
3155
3407
|
*/
|
|
3156
3408
|
async getMarketPools() {
|
|
3157
|
-
const response = await this.
|
|
3158
|
-
|
|
3159
|
-
return response.data.pools.reduce((marketPools, marketPool) => {
|
|
3160
|
-
marketPools[marketPool.coinName] = marketPool;
|
|
3161
|
-
return marketPools;
|
|
3162
|
-
}, {});
|
|
3163
|
-
} else {
|
|
3164
|
-
throw Error("Failed to getMarketPools.");
|
|
3165
|
-
}
|
|
3409
|
+
const response = (await this.getMarket()).pools;
|
|
3410
|
+
return response;
|
|
3166
3411
|
}
|
|
3167
3412
|
/**
|
|
3168
3413
|
* Get market pool index data.
|
|
@@ -3170,12 +3415,7 @@ var ScallopIndexer = class {
|
|
|
3170
3415
|
* @return Market pool data.
|
|
3171
3416
|
*/
|
|
3172
3417
|
async getMarketPool(poolCoinName) {
|
|
3173
|
-
|
|
3174
|
-
if (response.status === 200) {
|
|
3175
|
-
return response.data.pool;
|
|
3176
|
-
} else {
|
|
3177
|
-
throw Error("Failed to getMarketPool.");
|
|
3178
|
-
}
|
|
3418
|
+
return (await this.getMarketPools())[poolCoinName];
|
|
3179
3419
|
}
|
|
3180
3420
|
/**
|
|
3181
3421
|
* Get market collaterals index data.
|
|
@@ -3183,18 +3423,7 @@ var ScallopIndexer = class {
|
|
|
3183
3423
|
* @return Market collaterals data.
|
|
3184
3424
|
*/
|
|
3185
3425
|
async getMarketCollaterals() {
|
|
3186
|
-
|
|
3187
|
-
if (response.status === 200) {
|
|
3188
|
-
return response.data.collaterals.reduce(
|
|
3189
|
-
(marketCollaterals, marketCollateral) => {
|
|
3190
|
-
marketCollaterals[marketCollateral.coinName] = marketCollateral;
|
|
3191
|
-
return marketCollaterals;
|
|
3192
|
-
},
|
|
3193
|
-
{}
|
|
3194
|
-
);
|
|
3195
|
-
} else {
|
|
3196
|
-
throw Error("Failed to getMarketCollaterals.");
|
|
3197
|
-
}
|
|
3426
|
+
return (await this.getMarket()).collaterals;
|
|
3198
3427
|
}
|
|
3199
3428
|
/**
|
|
3200
3429
|
* Get market collateral index data.
|
|
@@ -3202,12 +3431,7 @@ var ScallopIndexer = class {
|
|
|
3202
3431
|
* @return Market collateral data.
|
|
3203
3432
|
*/
|
|
3204
3433
|
async getMarketCollateral(collateralCoinName) {
|
|
3205
|
-
|
|
3206
|
-
if (response.status === 200) {
|
|
3207
|
-
return response.data.collateral;
|
|
3208
|
-
} else {
|
|
3209
|
-
throw Error("Failed to getMarketCollateral.");
|
|
3210
|
-
}
|
|
3434
|
+
return (await this.getMarketCollaterals())[collateralCoinName];
|
|
3211
3435
|
}
|
|
3212
3436
|
/**
|
|
3213
3437
|
* Get spools index data.
|
|
@@ -3215,7 +3439,12 @@ var ScallopIndexer = class {
|
|
|
3215
3439
|
* @return Spools data.
|
|
3216
3440
|
*/
|
|
3217
3441
|
async getSpools() {
|
|
3218
|
-
const response = await this.
|
|
3442
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
3443
|
+
queryKey: ["spools"],
|
|
3444
|
+
queryFn: async () => {
|
|
3445
|
+
return await this._requestClient.get(`/api/spools`);
|
|
3446
|
+
}
|
|
3447
|
+
});
|
|
3219
3448
|
if (response.status === 200) {
|
|
3220
3449
|
return response.data.spools.reduce((spools, spool) => {
|
|
3221
3450
|
spools[spool.marketCoinName] = spool;
|
|
@@ -3231,12 +3460,7 @@ var ScallopIndexer = class {
|
|
|
3231
3460
|
* @return Spool data.
|
|
3232
3461
|
*/
|
|
3233
3462
|
async getSpool(marketCoinName) {
|
|
3234
|
-
|
|
3235
|
-
if (response.status === 200) {
|
|
3236
|
-
return response.data.spool;
|
|
3237
|
-
} else {
|
|
3238
|
-
throw Error("Failed to getSpool.");
|
|
3239
|
-
}
|
|
3463
|
+
return (await this.getSpools())[marketCoinName];
|
|
3240
3464
|
}
|
|
3241
3465
|
/**
|
|
3242
3466
|
* Get borrow incentive pools index data.
|
|
@@ -3244,7 +3468,12 @@ var ScallopIndexer = class {
|
|
|
3244
3468
|
* @return Borrow incentive pools data.
|
|
3245
3469
|
*/
|
|
3246
3470
|
async getBorrowIncentivePools() {
|
|
3247
|
-
const response = await this.
|
|
3471
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
3472
|
+
queryKey: ["borrowIncentivePools"],
|
|
3473
|
+
queryFn: async () => {
|
|
3474
|
+
return await this._requestClient.get(`/api/borrowIncentivePools`);
|
|
3475
|
+
}
|
|
3476
|
+
});
|
|
3248
3477
|
if (response.status === 200) {
|
|
3249
3478
|
return response.data.borrowIncentivePools.reduce(
|
|
3250
3479
|
(borrowIncentivePools, borrowIncentivePool) => {
|
|
@@ -3263,14 +3492,7 @@ var ScallopIndexer = class {
|
|
|
3263
3492
|
* @return Borrow incentive pool data.
|
|
3264
3493
|
*/
|
|
3265
3494
|
async getBorrowIncentivePool(borrowIncentiveCoinName) {
|
|
3266
|
-
|
|
3267
|
-
`${SDK_API_BASE_URL}/api/borrowIncentivePool/${borrowIncentiveCoinName}`
|
|
3268
|
-
);
|
|
3269
|
-
if (response.status === 200) {
|
|
3270
|
-
return response.data.borrowIncentivePool;
|
|
3271
|
-
} else {
|
|
3272
|
-
throw Error("Failed to getSpool.");
|
|
3273
|
-
}
|
|
3495
|
+
return (await this.getBorrowIncentivePools())[borrowIncentiveCoinName];
|
|
3274
3496
|
}
|
|
3275
3497
|
/**
|
|
3276
3498
|
* Get total value locked index data.
|
|
@@ -3278,7 +3500,12 @@ var ScallopIndexer = class {
|
|
|
3278
3500
|
* @return Total value locked.
|
|
3279
3501
|
*/
|
|
3280
3502
|
async getTotalValueLocked() {
|
|
3281
|
-
const response = await this.
|
|
3503
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
3504
|
+
queryKey: ["totalValueLocked"],
|
|
3505
|
+
queryFn: async () => {
|
|
3506
|
+
return await this._requestClient.get(`/api/market/tvl`);
|
|
3507
|
+
}
|
|
3508
|
+
});
|
|
3282
3509
|
if (response.status === 200) {
|
|
3283
3510
|
return response.data;
|
|
3284
3511
|
} else {
|
|
@@ -3291,17 +3518,22 @@ var ScallopIndexer = class {
|
|
|
3291
3518
|
var ScallopQuery = class {
|
|
3292
3519
|
constructor(params, instance) {
|
|
3293
3520
|
this.params = params;
|
|
3294
|
-
this.suiKit = instance?.suiKit ?? new
|
|
3295
|
-
this.
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3521
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit2.SuiKit(params);
|
|
3522
|
+
this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
|
|
3523
|
+
this.address = instance?.address ?? new ScallopAddress(
|
|
3524
|
+
{
|
|
3525
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
3526
|
+
network: params?.networkType
|
|
3527
|
+
},
|
|
3528
|
+
this.cache
|
|
3529
|
+
);
|
|
3299
3530
|
this.utils = instance?.utils ?? new ScallopUtils(this.params, {
|
|
3300
3531
|
suiKit: this.suiKit,
|
|
3301
3532
|
address: this.address,
|
|
3533
|
+
cache: this.cache,
|
|
3302
3534
|
query: this
|
|
3303
3535
|
});
|
|
3304
|
-
this.indexer = new ScallopIndexer();
|
|
3536
|
+
this.indexer = new ScallopIndexer(this.params, { cache: this.cache });
|
|
3305
3537
|
}
|
|
3306
3538
|
/**
|
|
3307
3539
|
* Request the scallop API to initialize data.
|
|
@@ -3639,6 +3871,22 @@ var ScallopQuery = class {
|
|
|
3639
3871
|
async getTvl(indexer = false) {
|
|
3640
3872
|
return await getTotalValueLocked(this, indexer);
|
|
3641
3873
|
}
|
|
3874
|
+
/**
|
|
3875
|
+
* Get binded obligationId from a veScaKey if it exists.
|
|
3876
|
+
* @param veScaKey
|
|
3877
|
+
* @returns obligationId
|
|
3878
|
+
*/
|
|
3879
|
+
async getBindedObligationId(veScaKey) {
|
|
3880
|
+
return await getBindedObligationId(this, veScaKey);
|
|
3881
|
+
}
|
|
3882
|
+
/**
|
|
3883
|
+
* Get binded veSCA key from a obligationId if it exists.
|
|
3884
|
+
* @param obligationId
|
|
3885
|
+
* @returns veScaKey
|
|
3886
|
+
*/
|
|
3887
|
+
async getBindedVeScaKey(obligationId) {
|
|
3888
|
+
return await getBindedVeScaKey(this, obligationId);
|
|
3889
|
+
}
|
|
3642
3890
|
};
|
|
3643
3891
|
|
|
3644
3892
|
// src/constants/pyth.ts
|
|
@@ -3670,14 +3918,19 @@ var ScallopUtils = class {
|
|
|
3670
3918
|
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
3671
3919
|
};
|
|
3672
3920
|
this.params = params;
|
|
3673
|
-
this._suiKit = instance?.suiKit ?? new
|
|
3674
|
-
this.
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3921
|
+
this._suiKit = instance?.suiKit ?? new import_sui_kit3.SuiKit(params);
|
|
3922
|
+
this._cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this._suiKit);
|
|
3923
|
+
this._address = instance?.address ?? new ScallopAddress(
|
|
3924
|
+
{
|
|
3925
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
3926
|
+
network: params?.networkType
|
|
3927
|
+
},
|
|
3928
|
+
this._cache
|
|
3929
|
+
);
|
|
3678
3930
|
this._query = instance?.query ?? new ScallopQuery(params, {
|
|
3679
3931
|
suiKit: this._suiKit,
|
|
3680
|
-
address: this._address
|
|
3932
|
+
address: this._address,
|
|
3933
|
+
cache: this._cache
|
|
3681
3934
|
});
|
|
3682
3935
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
3683
3936
|
}
|
|
@@ -3894,33 +4147,52 @@ var ScallopUtils = class {
|
|
|
3894
4147
|
}
|
|
3895
4148
|
if (lackPricesCoinNames.length > 0) {
|
|
3896
4149
|
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
4150
|
+
const failedRequests = new Set(
|
|
4151
|
+
lackPricesCoinNames
|
|
4152
|
+
);
|
|
4153
|
+
for (const endpoint of endpoints) {
|
|
4154
|
+
let hasFailRequest = false;
|
|
4155
|
+
const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint);
|
|
4156
|
+
const priceIds = Array.from(failedRequests.values()).reduce(
|
|
4157
|
+
(acc, coinName) => {
|
|
4158
|
+
const priceId = this._address.get(
|
|
4159
|
+
`core.coins.${coinName}.oracle.pyth.feed`
|
|
3903
4160
|
);
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
4161
|
+
acc[coinName] = priceId;
|
|
4162
|
+
return acc;
|
|
4163
|
+
},
|
|
4164
|
+
{}
|
|
4165
|
+
);
|
|
4166
|
+
for (const [coinName, priceId] of Object.entries(priceIds)) {
|
|
4167
|
+
try {
|
|
4168
|
+
const feed = await this._cache.queryClient.fetchQuery({
|
|
4169
|
+
queryKey: [priceId],
|
|
4170
|
+
queryFn: async () => {
|
|
4171
|
+
return await pythConnection.getLatestPriceFeeds([priceId]);
|
|
4172
|
+
}
|
|
4173
|
+
// staleTime: 15000,
|
|
4174
|
+
});
|
|
4175
|
+
if (feed) {
|
|
4176
|
+
const data = parseDataFromPythPriceFeed(feed[0], this._address);
|
|
3908
4177
|
this._priceMap.set(coinName, {
|
|
3909
4178
|
price: data.price,
|
|
3910
4179
|
publishTime: data.publishTime
|
|
3911
4180
|
});
|
|
3912
4181
|
coinPrices[coinName] = data.price;
|
|
3913
4182
|
}
|
|
3914
|
-
|
|
4183
|
+
failedRequests.delete(coinName);
|
|
3915
4184
|
} catch (e) {
|
|
3916
4185
|
console.warn(
|
|
3917
|
-
`Failed to
|
|
4186
|
+
`Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
|
|
3918
4187
|
);
|
|
4188
|
+
hasFailRequest = true;
|
|
3919
4189
|
}
|
|
3920
|
-
throw new Error("Failed to update price feeds with all endpoins");
|
|
3921
4190
|
}
|
|
3922
|
-
|
|
3923
|
-
|
|
4191
|
+
if (!hasFailRequest)
|
|
4192
|
+
break;
|
|
4193
|
+
}
|
|
4194
|
+
if (failedRequests.size > 0) {
|
|
4195
|
+
for (const coinName of failedRequests.values()) {
|
|
3924
4196
|
const price = await this._query.getPriceFromPyth(coinName);
|
|
3925
4197
|
this._priceMap.set(coinName, {
|
|
3926
4198
|
price,
|
|
@@ -3988,12 +4260,12 @@ var ScallopUtils = class {
|
|
|
3988
4260
|
|
|
3989
4261
|
// src/models/scallopBuilder.ts
|
|
3990
4262
|
var import_utils19 = require("@mysten/sui.js/utils");
|
|
3991
|
-
var
|
|
4263
|
+
var import_sui_kit8 = require("@scallop-io/sui-kit");
|
|
3992
4264
|
|
|
3993
4265
|
// src/builders/coreBuilder.ts
|
|
3994
4266
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
3995
4267
|
var import_utils12 = require("@mysten/sui.js/utils");
|
|
3996
|
-
var
|
|
4268
|
+
var import_sui_kit4 = require("@scallop-io/sui-kit");
|
|
3997
4269
|
|
|
3998
4270
|
// src/builders/oracle.ts
|
|
3999
4271
|
var import_utils11 = require("@mysten/sui.js/utils");
|
|
@@ -4425,7 +4697,7 @@ var generateCoreQuickMethod = ({
|
|
|
4425
4697
|
};
|
|
4426
4698
|
};
|
|
4427
4699
|
var newCoreTxBlock = (builder, initTxBlock) => {
|
|
4428
|
-
const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new
|
|
4700
|
+
const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new import_sui_kit4.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit4.SuiTxBlock();
|
|
4429
4701
|
const normalMethod = generateCoreNormalMethod({
|
|
4430
4702
|
builder,
|
|
4431
4703
|
txBlock
|
|
@@ -4455,7 +4727,7 @@ var newCoreTxBlock = (builder, initTxBlock) => {
|
|
|
4455
4727
|
// src/builders/spoolBuilder.ts
|
|
4456
4728
|
var import_transactions2 = require("@mysten/sui.js/transactions");
|
|
4457
4729
|
var import_utils14 = require("@mysten/sui.js/utils");
|
|
4458
|
-
var
|
|
4730
|
+
var import_sui_kit5 = require("@scallop-io/sui-kit");
|
|
4459
4731
|
var requireStakeAccountIds = async (...params) => {
|
|
4460
4732
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
4461
4733
|
if (params.length === 4 && stakeAccountId)
|
|
@@ -4613,7 +4885,7 @@ var generateSpoolQuickMethod = ({
|
|
|
4613
4885
|
};
|
|
4614
4886
|
};
|
|
4615
4887
|
var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
4616
|
-
const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new
|
|
4888
|
+
const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new import_sui_kit5.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit5.SuiTxBlock();
|
|
4617
4889
|
const normalMethod = generateSpoolNormalMethod({
|
|
4618
4890
|
builder,
|
|
4619
4891
|
txBlock
|
|
@@ -4643,10 +4915,10 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
4643
4915
|
// src/builders/borrowIncentiveBuilder.ts
|
|
4644
4916
|
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
4645
4917
|
var import_utils17 = require("@mysten/sui.js/utils");
|
|
4646
|
-
var
|
|
4918
|
+
var import_sui_kit7 = require("@scallop-io/sui-kit");
|
|
4647
4919
|
|
|
4648
4920
|
// src/builders/vescaBuilder.ts
|
|
4649
|
-
var
|
|
4921
|
+
var import_sui_kit6 = require("@scallop-io/sui-kit");
|
|
4650
4922
|
var requireVeSca = async (...params) => {
|
|
4651
4923
|
const [builder, txBlock, veScaKey] = params;
|
|
4652
4924
|
if (params.length === 3 && veScaKey && typeof veScaKey === "string") {
|
|
@@ -4661,7 +4933,10 @@ var requireVeSca = async (...params) => {
|
|
|
4661
4933
|
if (veScas.length === 0) {
|
|
4662
4934
|
return void 0;
|
|
4663
4935
|
}
|
|
4664
|
-
return veScas
|
|
4936
|
+
return veScas.reduce(
|
|
4937
|
+
(prev, acc) => acc.currentVeScaBalance > prev.currentVeScaBalance ? acc : prev,
|
|
4938
|
+
veScas[0]
|
|
4939
|
+
);
|
|
4665
4940
|
};
|
|
4666
4941
|
var generateNormalVeScaMethod = ({
|
|
4667
4942
|
builder,
|
|
@@ -4683,7 +4958,7 @@ var generateNormalVeScaMethod = ({
|
|
|
4683
4958
|
veScaIds.treasury,
|
|
4684
4959
|
scaCoin,
|
|
4685
4960
|
unlockAtInSecondTimestamp,
|
|
4686
|
-
|
|
4961
|
+
import_sui_kit6.SUI_CLOCK_OBJECT_ID
|
|
4687
4962
|
],
|
|
4688
4963
|
[]
|
|
4689
4964
|
);
|
|
@@ -4697,7 +4972,7 @@ var generateNormalVeScaMethod = ({
|
|
|
4697
4972
|
veScaIds.table,
|
|
4698
4973
|
veScaIds.treasury,
|
|
4699
4974
|
newUnlockAtInSecondTimestamp,
|
|
4700
|
-
|
|
4975
|
+
import_sui_kit6.SUI_CLOCK_OBJECT_ID
|
|
4701
4976
|
],
|
|
4702
4977
|
[]
|
|
4703
4978
|
);
|
|
@@ -4711,7 +4986,7 @@ var generateNormalVeScaMethod = ({
|
|
|
4711
4986
|
veScaIds.table,
|
|
4712
4987
|
veScaIds.treasury,
|
|
4713
4988
|
scaCoin,
|
|
4714
|
-
|
|
4989
|
+
import_sui_kit6.SUI_CLOCK_OBJECT_ID
|
|
4715
4990
|
],
|
|
4716
4991
|
[]
|
|
4717
4992
|
);
|
|
@@ -4726,7 +5001,7 @@ var generateNormalVeScaMethod = ({
|
|
|
4726
5001
|
veScaIds.treasury,
|
|
4727
5002
|
scaCoin,
|
|
4728
5003
|
newUnlockAtInSecondTimestamp,
|
|
4729
|
-
|
|
5004
|
+
import_sui_kit6.SUI_CLOCK_OBJECT_ID
|
|
4730
5005
|
],
|
|
4731
5006
|
[]
|
|
4732
5007
|
);
|
|
@@ -4739,7 +5014,7 @@ var generateNormalVeScaMethod = ({
|
|
|
4739
5014
|
veScaKey,
|
|
4740
5015
|
veScaIds.table,
|
|
4741
5016
|
veScaIds.treasury,
|
|
4742
|
-
|
|
5017
|
+
import_sui_kit6.SUI_CLOCK_OBJECT_ID
|
|
4743
5018
|
],
|
|
4744
5019
|
[]
|
|
4745
5020
|
);
|
|
@@ -4795,7 +5070,7 @@ var generateQuickVeScaMethod = ({
|
|
|
4795
5070
|
const veScaKey = txBlock.lockSca(scaCoin, newUnlockAt);
|
|
4796
5071
|
transferObjects.push(veScaKey);
|
|
4797
5072
|
} else {
|
|
4798
|
-
if (veSca.
|
|
5073
|
+
if (veSca.lockedScaCoin !== 0) {
|
|
4799
5074
|
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
4800
5075
|
transferObjects.push(unlockedSca);
|
|
4801
5076
|
}
|
|
@@ -4855,7 +5130,7 @@ var generateQuickVeScaMethod = ({
|
|
|
4855
5130
|
checkRenewExpiredVeSca(scaAmount, lockPeriodInDays, veSca?.unlockAt);
|
|
4856
5131
|
if (veSca) {
|
|
4857
5132
|
const transferObjects = [];
|
|
4858
|
-
if (veSca.
|
|
5133
|
+
if (veSca.lockedScaCoin !== 0) {
|
|
4859
5134
|
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
4860
5135
|
transferObjects.push(unlockedSca);
|
|
4861
5136
|
}
|
|
@@ -4885,7 +5160,7 @@ var generateQuickVeScaMethod = ({
|
|
|
4885
5160
|
};
|
|
4886
5161
|
};
|
|
4887
5162
|
var newVeScaTxBlock = (builder, initTxBlock) => {
|
|
4888
|
-
const txBlock = initTxBlock instanceof
|
|
5163
|
+
const txBlock = initTxBlock instanceof import_sui_kit6.TransactionBlock ? new import_sui_kit6.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit6.SuiTxBlock();
|
|
4889
5164
|
const normalMethod = generateNormalVeScaMethod({
|
|
4890
5165
|
builder,
|
|
4891
5166
|
txBlock
|
|
@@ -4936,37 +5211,6 @@ var requireObligationInfo2 = async (...params) => {
|
|
|
4936
5211
|
obligationLocked: selectedObligation.locked
|
|
4937
5212
|
};
|
|
4938
5213
|
};
|
|
4939
|
-
var getBindedObligationId = async (builder, veScaKey) => {
|
|
4940
|
-
const borrowIncentiveObjectId = builder.address.get("borrowIncentive.object");
|
|
4941
|
-
const incentivePoolsId = builder.address.get(
|
|
4942
|
-
"borrowIncentive.incentivePools"
|
|
4943
|
-
);
|
|
4944
|
-
const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : builder.address.get("vesca.id");
|
|
4945
|
-
const client = builder.suiKit.client();
|
|
4946
|
-
const incentivePoolsResponse = await client.getObject({
|
|
4947
|
-
id: incentivePoolsId,
|
|
4948
|
-
options: {
|
|
4949
|
-
showContent: true
|
|
4950
|
-
}
|
|
4951
|
-
});
|
|
4952
|
-
if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
|
|
4953
|
-
return false;
|
|
4954
|
-
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
4955
|
-
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
4956
|
-
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
|
|
4957
|
-
const veScaBindTableResponse = await client.getDynamicFieldObject({
|
|
4958
|
-
parentId: veScaBindTableId,
|
|
4959
|
-
name: {
|
|
4960
|
-
type: keyType,
|
|
4961
|
-
value: veScaKey
|
|
4962
|
-
}
|
|
4963
|
-
});
|
|
4964
|
-
if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
|
|
4965
|
-
return false;
|
|
4966
|
-
const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
|
|
4967
|
-
const obligationId = veScaBindTableFields.value.fields.id;
|
|
4968
|
-
return obligationId;
|
|
4969
|
-
};
|
|
4970
5214
|
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
4971
5215
|
const borrowIncentiveIds = {
|
|
4972
5216
|
borrowIncentivePkg: IS_VE_SCA_TEST ? "0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246" : builder.address.get("borrowIncentive.id"),
|
|
@@ -5031,7 +5275,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
5031
5275
|
);
|
|
5032
5276
|
},
|
|
5033
5277
|
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
5034
|
-
const rewardCoinNames =
|
|
5278
|
+
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
5035
5279
|
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
5036
5280
|
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
5037
5281
|
}
|
|
@@ -5106,7 +5350,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
5106
5350
|
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
5107
5351
|
if (veSca) {
|
|
5108
5352
|
const bindedObligationId = await getBindedObligationId(
|
|
5109
|
-
builder,
|
|
5353
|
+
builder.query,
|
|
5110
5354
|
veSca.keyId
|
|
5111
5355
|
);
|
|
5112
5356
|
if (!bindedObligationId || bindedObligationId === obligationArg) {
|
|
@@ -5158,7 +5402,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
5158
5402
|
};
|
|
5159
5403
|
};
|
|
5160
5404
|
var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
5161
|
-
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new
|
|
5405
|
+
const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
|
|
5162
5406
|
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
5163
5407
|
builder,
|
|
5164
5408
|
txBlock
|
|
@@ -5212,19 +5456,25 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
5212
5456
|
var ScallopBuilder = class {
|
|
5213
5457
|
constructor(params, instance) {
|
|
5214
5458
|
this.params = params;
|
|
5215
|
-
this.suiKit = instance?.suiKit ?? new
|
|
5216
|
-
this.
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5459
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit8.SuiKit(params);
|
|
5460
|
+
this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
|
|
5461
|
+
this.address = instance?.address ?? new ScallopAddress(
|
|
5462
|
+
{
|
|
5463
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
5464
|
+
network: params?.networkType
|
|
5465
|
+
},
|
|
5466
|
+
this.cache
|
|
5467
|
+
);
|
|
5220
5468
|
this.query = instance?.query ?? new ScallopQuery(params, {
|
|
5221
5469
|
suiKit: this.suiKit,
|
|
5222
|
-
address: this.address
|
|
5470
|
+
address: this.address,
|
|
5471
|
+
cache: this.cache
|
|
5223
5472
|
});
|
|
5224
5473
|
this.utils = instance?.utils ?? new ScallopUtils(this.params, {
|
|
5225
5474
|
suiKit: this.suiKit,
|
|
5226
5475
|
address: this.address,
|
|
5227
|
-
query: this.query
|
|
5476
|
+
query: this.query,
|
|
5477
|
+
cache: this.cache
|
|
5228
5478
|
});
|
|
5229
5479
|
this.walletAddress = (0, import_utils19.normalizeSuiAddress)(
|
|
5230
5480
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
@@ -5305,25 +5555,32 @@ var ScallopBuilder = class {
|
|
|
5305
5555
|
var ScallopClient = class {
|
|
5306
5556
|
constructor(params, instance) {
|
|
5307
5557
|
this.params = params;
|
|
5308
|
-
this.suiKit = instance?.suiKit ?? new
|
|
5309
|
-
this.
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5558
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit9.SuiKit(params);
|
|
5559
|
+
this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
|
|
5560
|
+
this.address = instance?.address ?? new ScallopAddress(
|
|
5561
|
+
{
|
|
5562
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
5563
|
+
network: params?.networkType
|
|
5564
|
+
},
|
|
5565
|
+
this.cache
|
|
5566
|
+
);
|
|
5313
5567
|
this.query = instance?.query ?? new ScallopQuery(params, {
|
|
5314
5568
|
suiKit: this.suiKit,
|
|
5315
|
-
address: this.address
|
|
5569
|
+
address: this.address,
|
|
5570
|
+
cache: this.cache
|
|
5316
5571
|
});
|
|
5317
5572
|
this.utils = instance?.utils ?? new ScallopUtils(params, {
|
|
5318
5573
|
suiKit: this.suiKit,
|
|
5319
5574
|
address: this.address,
|
|
5320
|
-
query: this.query
|
|
5575
|
+
query: this.query,
|
|
5576
|
+
cache: this.cache
|
|
5321
5577
|
});
|
|
5322
5578
|
this.builder = instance?.builder ?? new ScallopBuilder(params, {
|
|
5323
5579
|
suiKit: this.suiKit,
|
|
5324
5580
|
address: this.address,
|
|
5325
5581
|
query: this.query,
|
|
5326
|
-
utils: this.utils
|
|
5582
|
+
utils: this.utils,
|
|
5583
|
+
cache: this.cache
|
|
5327
5584
|
});
|
|
5328
5585
|
this.walletAddress = (0, import_utils20.normalizeSuiAddress)(
|
|
5329
5586
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
@@ -5829,13 +6086,20 @@ var ScallopClient = class {
|
|
|
5829
6086
|
|
|
5830
6087
|
// src/models/scallop.ts
|
|
5831
6088
|
var Scallop = class {
|
|
5832
|
-
constructor(params) {
|
|
6089
|
+
constructor(params, cacheOptions) {
|
|
5833
6090
|
this.params = params;
|
|
5834
|
-
this.suiKit = new
|
|
5835
|
-
this.
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
6091
|
+
this.suiKit = new import_sui_kit10.SuiKit(params);
|
|
6092
|
+
this.cache = new ScallopCache(
|
|
6093
|
+
cacheOptions ?? DEFAULT_CACHE_OPTIONS,
|
|
6094
|
+
this.suiKit
|
|
6095
|
+
);
|
|
6096
|
+
this._address = new ScallopAddress(
|
|
6097
|
+
{
|
|
6098
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
6099
|
+
network: params?.networkType
|
|
6100
|
+
},
|
|
6101
|
+
this.cache
|
|
6102
|
+
);
|
|
5839
6103
|
}
|
|
5840
6104
|
/**
|
|
5841
6105
|
* Get a scallop address instance that already has read addresses.
|
|
@@ -5857,7 +6121,8 @@ var Scallop = class {
|
|
|
5857
6121
|
await this._address.read();
|
|
5858
6122
|
const scallopBuilder = new ScallopBuilder(this.params, {
|
|
5859
6123
|
suiKit: this.suiKit,
|
|
5860
|
-
address: this._address
|
|
6124
|
+
address: this._address,
|
|
6125
|
+
cache: this.cache
|
|
5861
6126
|
});
|
|
5862
6127
|
return scallopBuilder;
|
|
5863
6128
|
}
|
|
@@ -5872,7 +6137,7 @@ var Scallop = class {
|
|
|
5872
6137
|
await this._address.read();
|
|
5873
6138
|
const scallopClient = new ScallopClient(
|
|
5874
6139
|
{ ...this.params, walletAddress },
|
|
5875
|
-
{ suiKit: this.suiKit, address: this._address }
|
|
6140
|
+
{ suiKit: this.suiKit, address: this._address, cache: this.cache }
|
|
5876
6141
|
);
|
|
5877
6142
|
return scallopClient;
|
|
5878
6143
|
}
|
|
@@ -5886,7 +6151,8 @@ var Scallop = class {
|
|
|
5886
6151
|
await this._address.read();
|
|
5887
6152
|
const scallopQuery = new ScallopQuery(this.params, {
|
|
5888
6153
|
suiKit: this.suiKit,
|
|
5889
|
-
address: this._address
|
|
6154
|
+
address: this._address,
|
|
6155
|
+
cache: this.cache
|
|
5890
6156
|
});
|
|
5891
6157
|
return scallopQuery;
|
|
5892
6158
|
}
|
|
@@ -5896,7 +6162,9 @@ var Scallop = class {
|
|
|
5896
6162
|
* @return Scallop Indexer.
|
|
5897
6163
|
*/
|
|
5898
6164
|
async createScallopIndexer() {
|
|
5899
|
-
const scallopIndexer = new ScallopIndexer(
|
|
6165
|
+
const scallopIndexer = new ScallopIndexer(this.params, {
|
|
6166
|
+
cache: this.cache
|
|
6167
|
+
});
|
|
5900
6168
|
return scallopIndexer;
|
|
5901
6169
|
}
|
|
5902
6170
|
/**
|
|
@@ -5909,7 +6177,8 @@ var Scallop = class {
|
|
|
5909
6177
|
await this._address.read();
|
|
5910
6178
|
const scallopUtils = new ScallopUtils(this.params, {
|
|
5911
6179
|
suiKit: this.suiKit,
|
|
5912
|
-
address: this._address
|
|
6180
|
+
address: this._address,
|
|
6181
|
+
cache: this.cache
|
|
5913
6182
|
});
|
|
5914
6183
|
return scallopUtils;
|
|
5915
6184
|
}
|
|
@@ -5939,6 +6208,7 @@ var Scallop = class {
|
|
|
5939
6208
|
Scallop,
|
|
5940
6209
|
ScallopAddress,
|
|
5941
6210
|
ScallopBuilder,
|
|
6211
|
+
ScallopCache,
|
|
5942
6212
|
ScallopClient,
|
|
5943
6213
|
ScallopIndexer,
|
|
5944
6214
|
ScallopQuery,
|