@scallop-io/sui-scallop-sdk 0.44.28 → 0.46.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 +1 -1
- package/dist/builders/referralBuilder.d.ts +12 -0
- package/dist/constants/cache.d.ts +8 -0
- package/dist/constants/common.d.ts +1 -1
- package/dist/index.js +890 -419
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +967 -493
- 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 +75 -0
- package/dist/models/scallopClient.d.ts +2 -0
- package/dist/models/scallopIndexer.d.ts +5 -3
- package/dist/models/scallopQuery.d.ts +28 -28
- package/dist/models/scallopUtils.d.ts +1 -0
- package/dist/queries/coreQuery.d.ts +3 -29
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/priceQuery.d.ts +3 -1
- package/dist/queries/referralQuery.d.ts +7 -0
- package/dist/queries/vescaQuery.d.ts +6 -2
- package/dist/types/address.d.ts +15 -0
- package/dist/types/builder/core.d.ts +2 -0
- package/dist/types/builder/index.d.ts +2 -1
- package/dist/types/builder/referral.d.ts +30 -0
- package/dist/types/builder/vesca.d.ts +1 -0
- package/dist/types/model.d.ts +2 -0
- package/package.json +8 -6
- package/src/builders/borrowIncentiveBuilder.ts +12 -21
- package/src/builders/coreBuilder.ts +54 -0
- package/src/builders/index.ts +5 -2
- package/src/builders/referralBuilder.ts +178 -0
- package/src/builders/vescaBuilder.ts +8 -6
- package/src/constants/cache.ts +15 -0
- package/src/constants/common.ts +9 -2
- package/src/constants/vesca.ts +1 -3
- package/src/models/index.ts +1 -0
- package/src/models/scallop.ts +26 -7
- package/src/models/scallopAddress.ts +87 -38
- package/src/models/scallopBuilder.ts +14 -4
- package/src/models/scallopCache.ts +285 -0
- package/src/models/scallopClient.ts +15 -4
- package/src/models/scallopIndexer.ts +58 -84
- package/src/models/scallopQuery.ts +54 -5
- package/src/models/scallopUtils.ts +66 -37
- package/src/queries/borrowIncentiveQuery.ts +6 -12
- package/src/queries/coreQuery.ts +83 -260
- package/src/queries/index.ts +1 -0
- package/src/queries/priceQuery.ts +48 -9
- package/src/queries/referralQuery.ts +27 -0
- package/src/queries/spoolQuery.ts +20 -27
- package/src/queries/vescaQuery.ts +95 -17
- package/src/types/address.ts +15 -0
- package/src/types/builder/core.ts +14 -0
- package/src/types/builder/index.ts +2 -0
- package/src/types/builder/referral.ts +51 -0
- package/src/types/builder/vesca.ts +1 -0
- package/src/types/model.ts +2 -0
- package/src/types/query/borrowIncentive.ts +0 -107
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,
|
|
@@ -74,7 +75,10 @@ module.exports = __toCommonJS(src_exports);
|
|
|
74
75
|
var API_BASE_URL = "https://sui.api.scallop.io";
|
|
75
76
|
var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
|
|
76
77
|
var IS_VE_SCA_TEST = false;
|
|
77
|
-
var ADDRESSES_ID = IS_VE_SCA_TEST ?
|
|
78
|
+
var ADDRESSES_ID = IS_VE_SCA_TEST ? (
|
|
79
|
+
// ? ('65fb07c39c845425d71d7b18' as const)
|
|
80
|
+
"65fb07c39c845425d71d7b18"
|
|
81
|
+
) : "664dfe22898c36c159e28bc8";
|
|
78
82
|
var PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
|
|
79
83
|
var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
|
|
80
84
|
var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
|
|
@@ -258,13 +262,233 @@ var voloCoinIds = {
|
|
|
258
262
|
|
|
259
263
|
// src/constants/vesca.ts
|
|
260
264
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
261
|
-
var MAX_LOCK_ROUNDS =
|
|
265
|
+
var MAX_LOCK_ROUNDS = 1460;
|
|
262
266
|
var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
263
267
|
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
264
268
|
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
265
269
|
|
|
266
270
|
// src/models/scallop.ts
|
|
267
|
-
var
|
|
271
|
+
var import_sui_kit12 = require("@scallop-io/sui-kit");
|
|
272
|
+
|
|
273
|
+
// src/models/scallopCache.ts
|
|
274
|
+
var import_query_core = require("@tanstack/query-core");
|
|
275
|
+
var import_sui_kit = require("@scallop-io/sui-kit");
|
|
276
|
+
|
|
277
|
+
// src/constants/cache.ts
|
|
278
|
+
var DEFAULT_CACHE_OPTIONS = {
|
|
279
|
+
defaultOptions: {
|
|
280
|
+
queries: {
|
|
281
|
+
staleTime: 3e3
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/models/scallopCache.ts
|
|
287
|
+
var ScallopCache = class {
|
|
288
|
+
constructor(cacheOptions, suiKit) {
|
|
289
|
+
this.queryClient = new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
290
|
+
this._suiKit = suiKit;
|
|
291
|
+
}
|
|
292
|
+
get suiKit() {
|
|
293
|
+
if (!this._suiKit) {
|
|
294
|
+
throw new Error("SuiKit instance is not initialized");
|
|
295
|
+
}
|
|
296
|
+
return this._suiKit;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* @description Invalidate cache based on the refetchType parameter
|
|
300
|
+
* @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
|
|
301
|
+
*
|
|
302
|
+
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
303
|
+
* - `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.
|
|
304
|
+
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
305
|
+
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
306
|
+
*/
|
|
307
|
+
invalidateAndRefetchAllCache(refetchType) {
|
|
308
|
+
return this.queryClient.invalidateQueries({
|
|
309
|
+
refetchType
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* @description Cache protocol config call for 60 seconds.
|
|
314
|
+
* @returns Promise<ProtocolConfig>
|
|
315
|
+
*/
|
|
316
|
+
async getProtocolConfig() {
|
|
317
|
+
return await this.queryClient.fetchQuery({
|
|
318
|
+
queryKey: ["getProtocolConfig"],
|
|
319
|
+
queryFn: async () => {
|
|
320
|
+
return await this.suiKit.client().getProtocolConfig();
|
|
321
|
+
},
|
|
322
|
+
staleTime: 3e4
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* @description Provides cache for inspectTxn of the SuiKit.
|
|
327
|
+
* @param QueryInspectTxnParams
|
|
328
|
+
* @param txBlock
|
|
329
|
+
* @returns Promise<DevInspectResults>
|
|
330
|
+
*/
|
|
331
|
+
async queryInspectTxn({
|
|
332
|
+
queryTarget,
|
|
333
|
+
args,
|
|
334
|
+
typeArgs
|
|
335
|
+
}) {
|
|
336
|
+
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
337
|
+
const resolvedArgs = await Promise.all(
|
|
338
|
+
args.map(async (arg) => {
|
|
339
|
+
if (typeof arg === "string") {
|
|
340
|
+
return (await this.queryGetObject(arg, { showContent: true })).data;
|
|
341
|
+
}
|
|
342
|
+
return arg;
|
|
343
|
+
})
|
|
344
|
+
);
|
|
345
|
+
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
346
|
+
const txBytes = await txBlock.txBlock.build({
|
|
347
|
+
client: this.suiKit.client(),
|
|
348
|
+
onlyTransactionKind: true,
|
|
349
|
+
protocolConfig: await this.getProtocolConfig()
|
|
350
|
+
});
|
|
351
|
+
const query = await this.queryClient.fetchQuery({
|
|
352
|
+
queryKey: typeArgs ? ["inspectTxn", queryTarget, JSON.stringify(args)] : [
|
|
353
|
+
"inspectTxn",
|
|
354
|
+
queryTarget,
|
|
355
|
+
JSON.stringify(args),
|
|
356
|
+
JSON.stringify(typeArgs)
|
|
357
|
+
],
|
|
358
|
+
queryFn: async () => {
|
|
359
|
+
return await this.suiKit.inspectTxn(txBytes);
|
|
360
|
+
},
|
|
361
|
+
staleTime: 8e3
|
|
362
|
+
// make stale time longer for inspectTxn results
|
|
363
|
+
});
|
|
364
|
+
return query;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* @description Provides cache for getObject of the SuiKit.
|
|
368
|
+
* @param objectId
|
|
369
|
+
* @param QueryObjectParams
|
|
370
|
+
* @returns Promise<SuiObjectResponse>
|
|
371
|
+
*/
|
|
372
|
+
async queryGetObject(objectId, options) {
|
|
373
|
+
const queryKey = ["getObject", objectId, this.suiKit.currentAddress()];
|
|
374
|
+
if (options) {
|
|
375
|
+
queryKey.push(JSON.stringify(options));
|
|
376
|
+
}
|
|
377
|
+
return this.queryClient.fetchQuery({
|
|
378
|
+
queryKey,
|
|
379
|
+
queryFn: async () => {
|
|
380
|
+
return await this.suiKit.client().getObject({
|
|
381
|
+
id: objectId,
|
|
382
|
+
options
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* @description Provides cache for getObjects of the SuiKit.
|
|
389
|
+
* @param objectIds
|
|
390
|
+
* @returns Promise<SuiObjectData[]>
|
|
391
|
+
*/
|
|
392
|
+
async queryGetObjects(objectIds, options) {
|
|
393
|
+
const queryKey = [
|
|
394
|
+
"getObjects",
|
|
395
|
+
JSON.stringify(objectIds),
|
|
396
|
+
this.suiKit.currentAddress()
|
|
397
|
+
];
|
|
398
|
+
return this.queryClient.fetchQuery({
|
|
399
|
+
queryKey,
|
|
400
|
+
queryFn: async () => {
|
|
401
|
+
return await this.suiKit.getObjects(objectIds, options);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* @description Provides cache for getOwnedObjects of the SuiKit.
|
|
407
|
+
* @param input
|
|
408
|
+
* @returns Promise<PaginatedObjectsResponse>
|
|
409
|
+
*/
|
|
410
|
+
async queryGetOwnedObjects(input) {
|
|
411
|
+
const queryKey = ["getOwnedObjects", input.owner];
|
|
412
|
+
if (input.cursor) {
|
|
413
|
+
queryKey.push(JSON.stringify(input.cursor));
|
|
414
|
+
}
|
|
415
|
+
if (input.options) {
|
|
416
|
+
queryKey.push(JSON.stringify(input.options));
|
|
417
|
+
}
|
|
418
|
+
if (input.filter) {
|
|
419
|
+
queryKey.push(JSON.stringify(input.filter));
|
|
420
|
+
}
|
|
421
|
+
if (input.limit) {
|
|
422
|
+
queryKey.push(JSON.stringify(input.limit));
|
|
423
|
+
}
|
|
424
|
+
return this.queryClient.fetchQuery({
|
|
425
|
+
queryKey,
|
|
426
|
+
queryFn: async () => {
|
|
427
|
+
return await this.suiKit.client().getOwnedObjects(input);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
async queryGetDynamicFields(input) {
|
|
432
|
+
const queryKey = ["getDynamicFields", input.parentId];
|
|
433
|
+
if (input.cursor) {
|
|
434
|
+
queryKey.push(JSON.stringify(input.cursor));
|
|
435
|
+
}
|
|
436
|
+
if (input.cursor) {
|
|
437
|
+
queryKey.push(JSON.stringify(input.cursor));
|
|
438
|
+
}
|
|
439
|
+
if (input.limit) {
|
|
440
|
+
queryKey.push(JSON.stringify(input.limit));
|
|
441
|
+
}
|
|
442
|
+
return this.queryClient.fetchQuery({
|
|
443
|
+
queryKey,
|
|
444
|
+
queryFn: async () => {
|
|
445
|
+
return await this.suiKit.client().getDynamicFields(input);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
async queryGetDynamicFieldObject(input) {
|
|
450
|
+
const queryKey = [
|
|
451
|
+
"getDynamicFieldObject",
|
|
452
|
+
input.parentId,
|
|
453
|
+
input.name.value
|
|
454
|
+
];
|
|
455
|
+
return this.queryClient.fetchQuery({
|
|
456
|
+
queryKey,
|
|
457
|
+
queryFn: async () => {
|
|
458
|
+
return await this.suiKit.client().getDynamicFieldObject(input);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
async queryGetAllCoinBalances(owner) {
|
|
463
|
+
const queryKey = ["getAllCoinBalances", owner];
|
|
464
|
+
return this.queryClient.fetchQuery({
|
|
465
|
+
queryKey,
|
|
466
|
+
queryFn: async () => {
|
|
467
|
+
const allBalances = await this.suiKit.client().getAllBalances({ owner });
|
|
468
|
+
return allBalances.reduce(
|
|
469
|
+
(acc, coinBalance) => {
|
|
470
|
+
if (coinBalance.totalBalance !== "0") {
|
|
471
|
+
acc[(0, import_sui_kit.normalizeStructTag)(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
472
|
+
}
|
|
473
|
+
return acc;
|
|
474
|
+
},
|
|
475
|
+
{}
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
async queryGetCoinBalance(input) {
|
|
481
|
+
const queryKey = ["getCoinBalance", input.owner, input.coinType];
|
|
482
|
+
return this.queryClient.fetchQuery({
|
|
483
|
+
queryKey,
|
|
484
|
+
queryFn: async () => {
|
|
485
|
+
if (!input.coinType)
|
|
486
|
+
return "0";
|
|
487
|
+
return (await this.queryGetAllCoinBalances(input.owner))[(0, import_sui_kit.normalizeStructTag)(input.coinType)] ?? "0";
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
};
|
|
268
492
|
|
|
269
493
|
// src/models/scallopAddress.ts
|
|
270
494
|
var import_axios = __toESM(require("axios"));
|
|
@@ -278,6 +502,45 @@ var EMPTY_ADDRESSES = {
|
|
|
278
502
|
coinDecimalsRegistry: "",
|
|
279
503
|
obligationAccessStore: "",
|
|
280
504
|
coins: {
|
|
505
|
+
cetus: {
|
|
506
|
+
id: "",
|
|
507
|
+
metaData: "",
|
|
508
|
+
treasury: "",
|
|
509
|
+
oracle: {
|
|
510
|
+
supra: "",
|
|
511
|
+
switchboard: "",
|
|
512
|
+
pyth: {
|
|
513
|
+
feed: "",
|
|
514
|
+
feedObject: ""
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
apt: {
|
|
519
|
+
id: "",
|
|
520
|
+
metaData: "",
|
|
521
|
+
treasury: "",
|
|
522
|
+
oracle: {
|
|
523
|
+
supra: "",
|
|
524
|
+
switchboard: "",
|
|
525
|
+
pyth: {
|
|
526
|
+
feed: "",
|
|
527
|
+
feedObject: ""
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
},
|
|
531
|
+
sol: {
|
|
532
|
+
id: "",
|
|
533
|
+
metaData: "",
|
|
534
|
+
treasury: "",
|
|
535
|
+
oracle: {
|
|
536
|
+
supra: "",
|
|
537
|
+
switchboard: "",
|
|
538
|
+
pyth: {
|
|
539
|
+
feed: "",
|
|
540
|
+
feedObject: ""
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
},
|
|
281
544
|
btc: {
|
|
282
545
|
id: "",
|
|
283
546
|
metaData: "",
|
|
@@ -399,15 +662,8 @@ var EMPTY_ADDRESSES = {
|
|
|
399
662
|
oracles: {
|
|
400
663
|
xOracle: "",
|
|
401
664
|
xOracleCap: "",
|
|
402
|
-
supra: {
|
|
403
|
-
|
|
404
|
-
registryCap: "",
|
|
405
|
-
holder: ""
|
|
406
|
-
},
|
|
407
|
-
switchboard: {
|
|
408
|
-
registry: "",
|
|
409
|
-
registryCap: ""
|
|
410
|
-
},
|
|
665
|
+
supra: { registry: "", registryCap: "", holder: "" },
|
|
666
|
+
switchboard: { registry: "", registryCap: "" },
|
|
411
667
|
pyth: {
|
|
412
668
|
registry: "",
|
|
413
669
|
registryCap: "",
|
|
@@ -437,27 +693,25 @@ var EMPTY_ADDRESSES = {
|
|
|
437
693
|
id: "",
|
|
438
694
|
upgradeCap: ""
|
|
439
695
|
},
|
|
440
|
-
|
|
696
|
+
protocolWhitelist: {
|
|
441
697
|
id: "",
|
|
442
698
|
upgradeCap: ""
|
|
443
699
|
},
|
|
444
|
-
|
|
700
|
+
query: {
|
|
445
701
|
id: "",
|
|
446
702
|
upgradeCap: ""
|
|
447
703
|
},
|
|
448
|
-
|
|
704
|
+
supra: { id: "", upgradeCap: "" },
|
|
705
|
+
pyth: {
|
|
449
706
|
id: "",
|
|
450
707
|
upgradeCap: ""
|
|
451
708
|
},
|
|
709
|
+
switchboard: { id: "", upgradeCap: "" },
|
|
452
710
|
xOracle: {
|
|
453
711
|
id: "",
|
|
454
712
|
upgradeCap: ""
|
|
455
713
|
},
|
|
456
|
-
|
|
457
|
-
testCoin: {
|
|
458
|
-
id: "",
|
|
459
|
-
upgradeCap: ""
|
|
460
|
-
}
|
|
714
|
+
testCoin: { id: "", upgradeCap: "" }
|
|
461
715
|
}
|
|
462
716
|
},
|
|
463
717
|
spool: {
|
|
@@ -497,34 +751,45 @@ var EMPTY_ADDRESSES = {
|
|
|
497
751
|
id: "",
|
|
498
752
|
rewardPoolId: ""
|
|
499
753
|
}
|
|
500
|
-
}
|
|
754
|
+
},
|
|
755
|
+
config: ""
|
|
501
756
|
},
|
|
502
757
|
borrowIncentive: {
|
|
503
758
|
id: "",
|
|
504
759
|
adminCap: "",
|
|
505
760
|
object: "",
|
|
506
761
|
query: "",
|
|
507
|
-
config: "",
|
|
508
762
|
incentivePools: "",
|
|
509
|
-
incentiveAccounts: ""
|
|
763
|
+
incentiveAccounts: "",
|
|
764
|
+
config: ""
|
|
510
765
|
},
|
|
511
766
|
vesca: {
|
|
512
767
|
id: "",
|
|
768
|
+
object: "",
|
|
513
769
|
adminCap: "",
|
|
514
770
|
tableId: "",
|
|
515
771
|
table: "",
|
|
516
772
|
treasury: "",
|
|
517
773
|
config: ""
|
|
774
|
+
},
|
|
775
|
+
referral: {
|
|
776
|
+
id: "",
|
|
777
|
+
version: "",
|
|
778
|
+
object: "",
|
|
779
|
+
adminCap: "",
|
|
780
|
+
referralBindings: "",
|
|
781
|
+
bindingTableId: "",
|
|
782
|
+
referralRevenuePool: "",
|
|
783
|
+
revenueTableId: "",
|
|
784
|
+
referralTiers: "",
|
|
785
|
+
tiersTableId: "",
|
|
786
|
+
authorizedWitnessList: ""
|
|
518
787
|
}
|
|
519
788
|
};
|
|
520
789
|
var ScallopAddress = class {
|
|
521
|
-
constructor(params) {
|
|
790
|
+
constructor(params, cache) {
|
|
522
791
|
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();
|
|
792
|
+
this._cache = cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS);
|
|
528
793
|
this._requestClient = import_axios.default.create({
|
|
529
794
|
baseURL: API_BASE_URL,
|
|
530
795
|
headers: {
|
|
@@ -533,6 +798,11 @@ var ScallopAddress = class {
|
|
|
533
798
|
},
|
|
534
799
|
timeout: 3e4
|
|
535
800
|
});
|
|
801
|
+
if (auth)
|
|
802
|
+
this._auth = auth;
|
|
803
|
+
this._id = id;
|
|
804
|
+
this._network = network || "mainnet";
|
|
805
|
+
this._addressesMap = /* @__PURE__ */ new Map();
|
|
536
806
|
}
|
|
537
807
|
/**
|
|
538
808
|
* Get addresses API id.
|
|
@@ -656,7 +926,7 @@ var ScallopAddress = class {
|
|
|
656
926
|
this._addressesMap.clear();
|
|
657
927
|
this.setAddresses(targetAddresses, targetNetwork);
|
|
658
928
|
const response = await this._requestClient.post(
|
|
659
|
-
|
|
929
|
+
`/addresses`,
|
|
660
930
|
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
661
931
|
{
|
|
662
932
|
headers: {
|
|
@@ -693,14 +963,16 @@ var ScallopAddress = class {
|
|
|
693
963
|
async read(id) {
|
|
694
964
|
const addressesId = id || this._id || void 0;
|
|
695
965
|
if (addressesId !== void 0) {
|
|
696
|
-
const response = await this.
|
|
697
|
-
|
|
698
|
-
{
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
966
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
967
|
+
queryKey: ["api-getAddresses", addressesId],
|
|
968
|
+
queryFn: async () => {
|
|
969
|
+
return await this._requestClient.get(`/addresses/${addressesId}`, {
|
|
970
|
+
headers: {
|
|
971
|
+
"Content-Type": "application/json"
|
|
972
|
+
}
|
|
973
|
+
});
|
|
702
974
|
}
|
|
703
|
-
);
|
|
975
|
+
});
|
|
704
976
|
if (response.status === 200) {
|
|
705
977
|
for (const [network, addresses] of Object.entries(
|
|
706
978
|
response.data
|
|
@@ -754,7 +1026,7 @@ var ScallopAddress = class {
|
|
|
754
1026
|
}
|
|
755
1027
|
this.setAddresses(targetAddresses, targetNetwork);
|
|
756
1028
|
const response = await this._requestClient.put(
|
|
757
|
-
|
|
1029
|
+
`/addresses/${targetId}`,
|
|
758
1030
|
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
759
1031
|
{
|
|
760
1032
|
headers: {
|
|
@@ -796,7 +1068,7 @@ var ScallopAddress = class {
|
|
|
796
1068
|
throw Error("Require specific addresses id to be deleted.");
|
|
797
1069
|
if (apiKey !== void 0) {
|
|
798
1070
|
const response = await this._requestClient.delete(
|
|
799
|
-
|
|
1071
|
+
`/addresses/${targetId}`,
|
|
800
1072
|
{
|
|
801
1073
|
headers: {
|
|
802
1074
|
"Content-Type": "application/json",
|
|
@@ -818,8 +1090,8 @@ var ScallopAddress = class {
|
|
|
818
1090
|
};
|
|
819
1091
|
|
|
820
1092
|
// src/models/scallopClient.ts
|
|
821
|
-
var
|
|
822
|
-
var
|
|
1093
|
+
var import_utils21 = require("@mysten/sui.js/utils");
|
|
1094
|
+
var import_sui_kit11 = require("@scallop-io/sui-kit");
|
|
823
1095
|
|
|
824
1096
|
// src/models/scallopUtils.ts
|
|
825
1097
|
var import_utils9 = require("@mysten/sui.js/utils");
|
|
@@ -831,8 +1103,6 @@ var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
|
831
1103
|
|
|
832
1104
|
// src/queries/coreQuery.ts
|
|
833
1105
|
var import_utils2 = require("@mysten/sui.js/utils");
|
|
834
|
-
var import_sui_kit = require("@scallop-io/sui-kit");
|
|
835
|
-
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
836
1106
|
|
|
837
1107
|
// src/utils/builder.ts
|
|
838
1108
|
var requireSender = (txBlock) => {
|
|
@@ -1380,13 +1650,16 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
|
1380
1650
|
};
|
|
1381
1651
|
|
|
1382
1652
|
// src/queries/coreQuery.ts
|
|
1653
|
+
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
1383
1654
|
var queryMarket = async (query, indexer = false) => {
|
|
1384
1655
|
const packageId = query.address.get("core.packages.query.id");
|
|
1385
1656
|
const marketId = query.address.get("core.market");
|
|
1386
|
-
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
1387
1657
|
const queryTarget = `${packageId}::market_query::market_data`;
|
|
1388
|
-
|
|
1389
|
-
const queryResult = await query.
|
|
1658
|
+
const args = [marketId];
|
|
1659
|
+
const queryResult = await query.cache.queryInspectTxn(
|
|
1660
|
+
{ queryTarget, args }
|
|
1661
|
+
// txBlock
|
|
1662
|
+
);
|
|
1390
1663
|
const marketData = queryResult.events[0].parsedJson;
|
|
1391
1664
|
const coinPrices = await query.utils.getCoinPrices();
|
|
1392
1665
|
const pools = {};
|
|
@@ -1504,11 +1777,8 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
1504
1777
|
var getMarketPools = async (query, poolCoinNames, indexer = false) => {
|
|
1505
1778
|
poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
|
|
1506
1779
|
const marketId = query.address.get("core.market");
|
|
1507
|
-
const marketObjectResponse = await query.
|
|
1508
|
-
|
|
1509
|
-
options: {
|
|
1510
|
-
showContent: true
|
|
1511
|
-
}
|
|
1780
|
+
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
1781
|
+
showContent: true
|
|
1512
1782
|
});
|
|
1513
1783
|
const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
|
|
1514
1784
|
const marketPools = {};
|
|
@@ -1541,11 +1811,8 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
|
|
|
1541
1811
|
};
|
|
1542
1812
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
1543
1813
|
const marketId = query.address.get("core.market");
|
|
1544
|
-
marketObject = marketObject || (await query.
|
|
1545
|
-
|
|
1546
|
-
options: {
|
|
1547
|
-
showContent: true
|
|
1548
|
-
}
|
|
1814
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
1815
|
+
showContent: true
|
|
1549
1816
|
})).data;
|
|
1550
1817
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
1551
1818
|
let marketPool;
|
|
@@ -1566,7 +1833,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1566
1833
|
const fields = marketObject.content.fields;
|
|
1567
1834
|
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
1568
1835
|
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
1569
|
-
const balanceSheetDynamicFieldObjectResponse = await query.
|
|
1836
|
+
const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1570
1837
|
parentId: balanceSheetParentId,
|
|
1571
1838
|
name: {
|
|
1572
1839
|
type: "0x1::type_name::TypeName",
|
|
@@ -1581,7 +1848,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1581
1848
|
balanceSheet = dynamicFields.value.fields;
|
|
1582
1849
|
}
|
|
1583
1850
|
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
1584
|
-
const borrowIndexDynamicFieldObjectResponse = await query.
|
|
1851
|
+
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1585
1852
|
parentId: borrowIndexParentId,
|
|
1586
1853
|
name: {
|
|
1587
1854
|
type: "0x1::type_name::TypeName",
|
|
@@ -1596,7 +1863,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1596
1863
|
borrowIndex = dynamicFields.value.fields;
|
|
1597
1864
|
}
|
|
1598
1865
|
const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
|
|
1599
|
-
const interestModelDynamicFieldObjectResponse = await query.
|
|
1866
|
+
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1600
1867
|
parentId: interestModelParentId,
|
|
1601
1868
|
name: {
|
|
1602
1869
|
type: "0x1::type_name::TypeName",
|
|
@@ -1610,7 +1877,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1610
1877
|
const dynamicFields = interestModelDynamicFieldObject.content.fields;
|
|
1611
1878
|
interestModel = dynamicFields.value.fields;
|
|
1612
1879
|
}
|
|
1613
|
-
const borrowFeeDynamicFieldObjectResponse = await query.
|
|
1880
|
+
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1614
1881
|
parentId: marketId,
|
|
1615
1882
|
name: {
|
|
1616
1883
|
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
@@ -1677,11 +1944,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
1677
1944
|
var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
|
|
1678
1945
|
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
1679
1946
|
const marketId = query.address.get("core.market");
|
|
1680
|
-
const marketObjectResponse = await query.
|
|
1681
|
-
|
|
1682
|
-
options: {
|
|
1683
|
-
showContent: true
|
|
1684
|
-
}
|
|
1947
|
+
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
1948
|
+
showContent: true
|
|
1685
1949
|
});
|
|
1686
1950
|
const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
|
|
1687
1951
|
const marketCollaterals = {};
|
|
@@ -1714,11 +1978,8 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
|
|
|
1714
1978
|
};
|
|
1715
1979
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
1716
1980
|
const marketId = query.address.get("core.market");
|
|
1717
|
-
marketObject = marketObject || (await query.
|
|
1718
|
-
|
|
1719
|
-
options: {
|
|
1720
|
-
showContent: true
|
|
1721
|
-
}
|
|
1981
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
1982
|
+
showContent: true
|
|
1722
1983
|
})).data;
|
|
1723
1984
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
1724
1985
|
let marketCollateral;
|
|
@@ -1737,7 +1998,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
1737
1998
|
const fields = marketObject.content.fields;
|
|
1738
1999
|
const coinType = query.utils.parseCoinType(collateralCoinName);
|
|
1739
2000
|
const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
|
|
1740
|
-
const riskModelDynamicFieldObjectResponse = await query.
|
|
2001
|
+
const riskModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1741
2002
|
parentId: riskModelParentId,
|
|
1742
2003
|
name: {
|
|
1743
2004
|
type: "0x1::type_name::TypeName",
|
|
@@ -1752,7 +2013,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
1752
2013
|
riskModel = dynamicFields.value.fields;
|
|
1753
2014
|
}
|
|
1754
2015
|
const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
|
|
1755
|
-
const collateralStatDynamicFieldObjectResponse = await query.
|
|
2016
|
+
const collateralStatDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
1756
2017
|
parentId: collateralStatParentId,
|
|
1757
2018
|
name: {
|
|
1758
2019
|
type: "0x1::type_name::TypeName",
|
|
@@ -1808,7 +2069,7 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1808
2069
|
let hasNextPage = false;
|
|
1809
2070
|
let nextCursor = null;
|
|
1810
2071
|
do {
|
|
1811
|
-
const paginatedKeyObjectsResponse = await query.
|
|
2072
|
+
const paginatedKeyObjectsResponse = await query.cache.queryGetOwnedObjects({
|
|
1812
2073
|
owner,
|
|
1813
2074
|
filter: {
|
|
1814
2075
|
StructType: `${protocolObjectId}::obligation::ObligationKey`
|
|
@@ -1824,7 +2085,7 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1824
2085
|
}
|
|
1825
2086
|
} while (hasNextPage);
|
|
1826
2087
|
const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
|
|
1827
|
-
const keyObjects = await query.
|
|
2088
|
+
const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
|
|
1828
2089
|
const obligations = [];
|
|
1829
2090
|
for (const keyObject of keyObjects) {
|
|
1830
2091
|
const keyId = keyObject.objectId;
|
|
@@ -1838,12 +2099,10 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
1838
2099
|
return obligations;
|
|
1839
2100
|
};
|
|
1840
2101
|
var getObligationLocked = async (query, obligationId) => {
|
|
1841
|
-
const obligationObjectResponse = await query.
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
}
|
|
1846
|
-
});
|
|
2102
|
+
const obligationObjectResponse = await query.cache.queryGetObject(
|
|
2103
|
+
obligationId,
|
|
2104
|
+
{ showContent: true }
|
|
2105
|
+
);
|
|
1847
2106
|
let obligationLocked = false;
|
|
1848
2107
|
if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
|
|
1849
2108
|
obligationLocked = Boolean(
|
|
@@ -1855,182 +2114,60 @@ var getObligationLocked = async (query, obligationId) => {
|
|
|
1855
2114
|
var queryObligation = async (query, obligationId) => {
|
|
1856
2115
|
const packageId = query.address.get("core.packages.query.id");
|
|
1857
2116
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
1858
|
-
const
|
|
1859
|
-
|
|
1860
|
-
|
|
2117
|
+
const args = [obligationId];
|
|
2118
|
+
const queryResult = await query.cache.queryInspectTxn(
|
|
2119
|
+
{ queryTarget, args }
|
|
2120
|
+
// txBlock
|
|
2121
|
+
);
|
|
1861
2122
|
return queryResult.events[0].parsedJson;
|
|
1862
2123
|
};
|
|
1863
2124
|
var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
|
|
1864
2125
|
assetCoinNames = assetCoinNames || [...SUPPORT_POOLS];
|
|
1865
2126
|
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
1866
|
-
const
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
filter: {
|
|
1873
|
-
MatchAny: assetCoinNames.map((assetCoinName) => {
|
|
1874
|
-
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
1875
|
-
return { StructType: `0x2::coin::Coin<${coinType}>` };
|
|
1876
|
-
})
|
|
1877
|
-
},
|
|
1878
|
-
options: {
|
|
1879
|
-
showType: true,
|
|
1880
|
-
showContent: true
|
|
1881
|
-
},
|
|
1882
|
-
cursor: nextCursor
|
|
1883
|
-
});
|
|
1884
|
-
coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
|
|
1885
|
-
if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
|
|
1886
|
-
hasNextPage = true;
|
|
1887
|
-
nextCursor = paginatedCoinObjectsResponse.nextCursor;
|
|
1888
|
-
} else {
|
|
1889
|
-
hasNextPage = false;
|
|
1890
|
-
}
|
|
1891
|
-
} while (hasNextPage);
|
|
1892
|
-
const coinAmounts = {};
|
|
1893
|
-
const coinObjects = coinObjectsResponse.map((response) => {
|
|
1894
|
-
return response.data;
|
|
1895
|
-
}).filter(
|
|
1896
|
-
(object) => object !== void 0 && object !== null
|
|
2127
|
+
const assetCoins2 = {};
|
|
2128
|
+
await Promise.allSettled(
|
|
2129
|
+
assetCoinNames.map(async (assetCoinName) => {
|
|
2130
|
+
const marketCoin = await getCoinAmount(query, assetCoinName, owner);
|
|
2131
|
+
assetCoins2[assetCoinName] = marketCoin;
|
|
2132
|
+
})
|
|
1897
2133
|
);
|
|
1898
|
-
|
|
1899
|
-
const type = coinObject.type;
|
|
1900
|
-
if (coinObject.content && "fields" in coinObject.content) {
|
|
1901
|
-
const fields = coinObject.content.fields;
|
|
1902
|
-
const poolCoinName = query.utils.parseCoinNameFromType(type);
|
|
1903
|
-
if (poolCoinName) {
|
|
1904
|
-
coinAmounts[poolCoinName] = (0, import_bignumber2.default)(coinAmounts[poolCoinName] ?? 0).plus(fields.balance).toNumber();
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
return coinAmounts;
|
|
2134
|
+
return assetCoins2;
|
|
1909
2135
|
};
|
|
1910
2136
|
var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
|
|
1911
2137
|
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
1912
2138
|
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
1913
|
-
const
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
owner,
|
|
1919
|
-
filter: { StructType: `0x2::coin::Coin<${coinType}>` },
|
|
1920
|
-
options: {
|
|
1921
|
-
showContent: true
|
|
1922
|
-
},
|
|
1923
|
-
cursor: nextCursor
|
|
1924
|
-
});
|
|
1925
|
-
coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
|
|
1926
|
-
if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
|
|
1927
|
-
hasNextPage = true;
|
|
1928
|
-
nextCursor = paginatedCoinObjectsResponse.nextCursor;
|
|
1929
|
-
} else {
|
|
1930
|
-
hasNextPage = false;
|
|
1931
|
-
}
|
|
1932
|
-
} while (hasNextPage);
|
|
1933
|
-
let coinAmount = 0;
|
|
1934
|
-
const coinObjects = coinObjectsResponse.map((response) => {
|
|
1935
|
-
return response.data;
|
|
1936
|
-
}).filter(
|
|
1937
|
-
(object) => object !== void 0 && object !== null
|
|
1938
|
-
);
|
|
1939
|
-
for (const coinObject of coinObjects) {
|
|
1940
|
-
if (coinObject.content && "fields" in coinObject.content) {
|
|
1941
|
-
const fields = coinObject.content.fields;
|
|
1942
|
-
coinAmount = (0, import_bignumber2.default)(coinAmount).plus(fields.balance).toNumber();
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1945
|
-
return coinAmount;
|
|
2139
|
+
const amount = await query.cache.queryGetCoinBalance({
|
|
2140
|
+
owner,
|
|
2141
|
+
coinType
|
|
2142
|
+
});
|
|
2143
|
+
return (0, import_bignumber2.default)(amount).toNumber();
|
|
1946
2144
|
};
|
|
1947
2145
|
var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
1948
2146
|
marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
|
|
1949
2147
|
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
1950
2148
|
);
|
|
1951
2149
|
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
})
|
|
1963
|
-
},
|
|
1964
|
-
options: {
|
|
1965
|
-
showType: true,
|
|
1966
|
-
showContent: true
|
|
1967
|
-
},
|
|
1968
|
-
cursor: nextCursor
|
|
1969
|
-
});
|
|
1970
|
-
marketCoinObjectsResponse.push(...paginatedMarketCoinObjectsResponse.data);
|
|
1971
|
-
if (paginatedMarketCoinObjectsResponse.hasNextPage && paginatedMarketCoinObjectsResponse.nextCursor) {
|
|
1972
|
-
hasNextPage = true;
|
|
1973
|
-
nextCursor = paginatedMarketCoinObjectsResponse.nextCursor;
|
|
1974
|
-
} else {
|
|
1975
|
-
hasNextPage = false;
|
|
1976
|
-
}
|
|
1977
|
-
} while (hasNextPage);
|
|
1978
|
-
const marketCoinAmounts = {};
|
|
1979
|
-
const marketCoinObjects = marketCoinObjectsResponse.map((response) => {
|
|
1980
|
-
return response.data;
|
|
1981
|
-
}).filter(
|
|
1982
|
-
(object) => object !== void 0 && object !== null
|
|
2150
|
+
const marketCoins2 = {};
|
|
2151
|
+
Promise.allSettled(
|
|
2152
|
+
marketCoinNames.map(async (marketCoinName) => {
|
|
2153
|
+
const marketCoin = await getMarketCoinAmount(
|
|
2154
|
+
query,
|
|
2155
|
+
marketCoinName,
|
|
2156
|
+
owner
|
|
2157
|
+
);
|
|
2158
|
+
marketCoins2[marketCoinName] = marketCoin;
|
|
2159
|
+
})
|
|
1983
2160
|
);
|
|
1984
|
-
|
|
1985
|
-
const marketCoinType = marketCoinObject.type;
|
|
1986
|
-
if (marketCoinObject.content && "fields" in marketCoinObject.content) {
|
|
1987
|
-
const fields = marketCoinObject.content.fields;
|
|
1988
|
-
const marketCoinName = query.utils.parseCoinNameFromType(marketCoinType);
|
|
1989
|
-
if (marketCoinName) {
|
|
1990
|
-
marketCoinAmounts[marketCoinName] = (0, import_bignumber2.default)(
|
|
1991
|
-
marketCoinAmounts[marketCoinName] ?? 0
|
|
1992
|
-
).plus(fields.balance).toNumber();
|
|
1993
|
-
}
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
return marketCoinAmounts;
|
|
2161
|
+
return marketCoins2;
|
|
1997
2162
|
};
|
|
1998
2163
|
var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
1999
2164
|
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
2000
2165
|
const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
|
|
2001
|
-
const
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
owner,
|
|
2007
|
-
filter: { StructType: `0x2::coin::Coin<${marketCoinType}>` },
|
|
2008
|
-
options: {
|
|
2009
|
-
showContent: true
|
|
2010
|
-
},
|
|
2011
|
-
cursor: nextCursor
|
|
2012
|
-
});
|
|
2013
|
-
marketCoinObjectsResponse.push(...paginatedMarketCoinObjectsResponse.data);
|
|
2014
|
-
if (paginatedMarketCoinObjectsResponse.hasNextPage && paginatedMarketCoinObjectsResponse.nextCursor) {
|
|
2015
|
-
hasNextPage = true;
|
|
2016
|
-
nextCursor = paginatedMarketCoinObjectsResponse.nextCursor;
|
|
2017
|
-
} else {
|
|
2018
|
-
hasNextPage = false;
|
|
2019
|
-
}
|
|
2020
|
-
} while (hasNextPage);
|
|
2021
|
-
let marketCoinAmount = 0;
|
|
2022
|
-
const marketCoinObjects = marketCoinObjectsResponse.map((response) => {
|
|
2023
|
-
return response.data;
|
|
2024
|
-
}).filter(
|
|
2025
|
-
(object) => object !== void 0 && object !== null
|
|
2026
|
-
);
|
|
2027
|
-
for (const marketCoinObject of marketCoinObjects) {
|
|
2028
|
-
if (marketCoinObject.content && "fields" in marketCoinObject.content) {
|
|
2029
|
-
const fields = marketCoinObject.content.fields;
|
|
2030
|
-
marketCoinAmount = (0, import_bignumber2.default)(marketCoinAmount).plus(fields.balance).toNumber();
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
return marketCoinAmount;
|
|
2166
|
+
const amount = await query.cache.queryGetCoinBalance({
|
|
2167
|
+
owner,
|
|
2168
|
+
coinType: marketCoinType
|
|
2169
|
+
});
|
|
2170
|
+
return (0, import_bignumber2.default)(amount).toNumber();
|
|
2034
2171
|
};
|
|
2035
2172
|
|
|
2036
2173
|
// src/queries/spoolQuery.ts
|
|
@@ -2100,17 +2237,17 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
2100
2237
|
spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName] || spoolIndexer.rewardCoinPrice;
|
|
2101
2238
|
return spoolIndexer;
|
|
2102
2239
|
}
|
|
2103
|
-
const spoolObjectResponse = await query.
|
|
2104
|
-
|
|
2105
|
-
|
|
2240
|
+
const spoolObjectResponse = await query.cache.queryGetObjects(
|
|
2241
|
+
[poolId, rewardPoolId],
|
|
2242
|
+
{
|
|
2106
2243
|
showContent: true
|
|
2107
2244
|
}
|
|
2108
|
-
|
|
2109
|
-
if (marketPool && spoolObjectResponse[0]
|
|
2245
|
+
);
|
|
2246
|
+
if (marketPool && spoolObjectResponse[0] && spoolObjectResponse[1]) {
|
|
2110
2247
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
2111
2248
|
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
2112
|
-
const spoolObject = spoolObjectResponse[0]
|
|
2113
|
-
const rewardPoolObject = spoolObjectResponse[1]
|
|
2249
|
+
const spoolObject = spoolObjectResponse[0];
|
|
2250
|
+
const rewardPoolObject = spoolObjectResponse[1];
|
|
2114
2251
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
2115
2252
|
const spoolFields = spoolObject.content.fields;
|
|
2116
2253
|
const parsedSpoolData = parseOriginSpoolData({
|
|
@@ -2182,7 +2319,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2182
2319
|
let hasNextPage = false;
|
|
2183
2320
|
let nextCursor = null;
|
|
2184
2321
|
do {
|
|
2185
|
-
const paginatedStakeObjectsResponse = await query.
|
|
2322
|
+
const paginatedStakeObjectsResponse = await query.cache.queryGetOwnedObjects({
|
|
2186
2323
|
owner,
|
|
2187
2324
|
filter: { StructType: stakeAccountType },
|
|
2188
2325
|
options: {
|
|
@@ -2220,7 +2357,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2220
2357
|
{}
|
|
2221
2358
|
);
|
|
2222
2359
|
const stakeObjectIds = stakeObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
|
|
2223
|
-
const stakeObjects = await query.
|
|
2360
|
+
const stakeObjects = await query.cache.queryGetObjects(stakeObjectIds);
|
|
2224
2361
|
for (const stakeObject of stakeObjects) {
|
|
2225
2362
|
const id = stakeObject.objectId;
|
|
2226
2363
|
const type = stakeObject.type;
|
|
@@ -2328,12 +2465,9 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2328
2465
|
var getStakePool = async (query, marketCoinName) => {
|
|
2329
2466
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
2330
2467
|
let stakePool = void 0;
|
|
2331
|
-
const stakePoolObjectResponse = await query.
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
showContent: true,
|
|
2335
|
-
showType: true
|
|
2336
|
-
}
|
|
2468
|
+
const stakePoolObjectResponse = await query.cache.queryGetObject(poolId, {
|
|
2469
|
+
showContent: true,
|
|
2470
|
+
showType: true
|
|
2337
2471
|
});
|
|
2338
2472
|
if (stakePoolObjectResponse.data) {
|
|
2339
2473
|
const stakePoolObject = stakePoolObjectResponse.data;
|
|
@@ -2374,13 +2508,13 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2374
2508
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
2375
2509
|
);
|
|
2376
2510
|
let stakeRewardPool = void 0;
|
|
2377
|
-
const stakeRewardPoolObjectResponse = await query.
|
|
2378
|
-
|
|
2379
|
-
|
|
2511
|
+
const stakeRewardPoolObjectResponse = await query.cache.queryGetObject(
|
|
2512
|
+
poolId,
|
|
2513
|
+
{
|
|
2380
2514
|
showContent: true,
|
|
2381
2515
|
showType: true
|
|
2382
2516
|
}
|
|
2383
|
-
|
|
2517
|
+
);
|
|
2384
2518
|
if (stakeRewardPoolObjectResponse.data) {
|
|
2385
2519
|
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
2386
2520
|
const id = stakeRewardPoolObject.objectId;
|
|
@@ -2410,17 +2544,15 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2410
2544
|
|
|
2411
2545
|
// src/queries/borrowIncentiveQuery.ts
|
|
2412
2546
|
var import_utils6 = require("@mysten/sui.js/utils");
|
|
2413
|
-
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
2414
2547
|
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
|
|
2415
2548
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2416
2549
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2417
2550
|
];
|
|
2418
2551
|
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2419
2552
|
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2420
|
-
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
2421
2553
|
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2422
|
-
|
|
2423
|
-
const queryResult = await query.
|
|
2554
|
+
const args = [incentivePoolsId];
|
|
2555
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2424
2556
|
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2425
2557
|
const borrowIncentivePools = {};
|
|
2426
2558
|
if (indexer) {
|
|
@@ -2497,9 +2629,8 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
|
|
|
2497
2629
|
"borrowIncentive.incentiveAccounts"
|
|
2498
2630
|
);
|
|
2499
2631
|
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
2500
|
-
const
|
|
2501
|
-
|
|
2502
|
-
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
2632
|
+
const args = [incentiveAccountsId, obligationId];
|
|
2633
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2503
2634
|
const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
|
|
2504
2635
|
const borrowIncentiveAccounts = Object.values(
|
|
2505
2636
|
borrowIncentiveAccountsQueryData.pool_records
|
|
@@ -2517,7 +2648,7 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
|
|
|
2517
2648
|
var getBindedObligationId = async (query, veScaKeyId) => {
|
|
2518
2649
|
const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
|
|
2519
2650
|
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2520
|
-
const
|
|
2651
|
+
const veScaObjId = query.address.get("vesca.object");
|
|
2521
2652
|
const client = query.suiKit.client();
|
|
2522
2653
|
const incentivePoolsResponse = await client.getObject({
|
|
2523
2654
|
id: incentivePoolsId,
|
|
@@ -2529,7 +2660,7 @@ var getBindedObligationId = async (query, veScaKeyId) => {
|
|
|
2529
2660
|
return null;
|
|
2530
2661
|
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
2531
2662
|
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
2532
|
-
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${
|
|
2663
|
+
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaObjId}::ve_sca::VeScaKey>`;
|
|
2533
2664
|
const veScaBindTableResponse = await client.getDynamicFieldObject({
|
|
2534
2665
|
parentId: veScaBindTableId,
|
|
2535
2666
|
name: {
|
|
@@ -2573,18 +2704,13 @@ var getBindedVeScaKey = async (query, obliationId) => {
|
|
|
2573
2704
|
};
|
|
2574
2705
|
|
|
2575
2706
|
// src/queries/priceQuery.ts
|
|
2576
|
-
var getPythPrice = async (query, assetCoinName) => {
|
|
2707
|
+
var getPythPrice = async (query, assetCoinName, priceFeedObject) => {
|
|
2577
2708
|
const pythFeedObjectId = query.address.get(
|
|
2578
2709
|
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
2579
2710
|
);
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
showContent: true
|
|
2584
|
-
}
|
|
2585
|
-
});
|
|
2586
|
-
if (priceFeedObjectResponse.data) {
|
|
2587
|
-
const priceFeedPoolObject = priceFeedObjectResponse.data;
|
|
2711
|
+
priceFeedObject = priceFeedObject || (await query.cache.queryGetObject(pythFeedObjectId, { showContent: true })).data;
|
|
2712
|
+
if (priceFeedObject) {
|
|
2713
|
+
const priceFeedPoolObject = priceFeedObject;
|
|
2588
2714
|
if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
|
|
2589
2715
|
const fields = priceFeedPoolObject.content.fields;
|
|
2590
2716
|
const expoMagnitude = Number(
|
|
@@ -2604,6 +2730,36 @@ var getPythPrice = async (query, assetCoinName) => {
|
|
|
2604
2730
|
}
|
|
2605
2731
|
return 0;
|
|
2606
2732
|
};
|
|
2733
|
+
var getPythPrices = async (query, assetCoinNames) => {
|
|
2734
|
+
const seen = {};
|
|
2735
|
+
const pythFeedObjectIds = assetCoinNames.map((assetCoinName) => {
|
|
2736
|
+
const pythFeedObjectId = query.address.get(
|
|
2737
|
+
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
2738
|
+
);
|
|
2739
|
+
if (seen[pythFeedObjectId])
|
|
2740
|
+
return null;
|
|
2741
|
+
seen[pythFeedObjectId] = true;
|
|
2742
|
+
return pythFeedObjectId;
|
|
2743
|
+
}).filter((item) => !!item);
|
|
2744
|
+
const priceFeedObjects = await query.cache.queryGetObjects(
|
|
2745
|
+
pythFeedObjectIds,
|
|
2746
|
+
{
|
|
2747
|
+
showContent: true
|
|
2748
|
+
}
|
|
2749
|
+
);
|
|
2750
|
+
return (await Promise.all(
|
|
2751
|
+
priceFeedObjects.map(async (priceFeedObject, idx) => ({
|
|
2752
|
+
coinName: assetCoinNames[idx],
|
|
2753
|
+
price: await getPythPrice(query, assetCoinNames[idx], priceFeedObject)
|
|
2754
|
+
}))
|
|
2755
|
+
)).reduce(
|
|
2756
|
+
(prev, curr) => {
|
|
2757
|
+
prev[curr.coinName] = curr.price;
|
|
2758
|
+
return prev;
|
|
2759
|
+
},
|
|
2760
|
+
{}
|
|
2761
|
+
);
|
|
2762
|
+
};
|
|
2607
2763
|
|
|
2608
2764
|
// src/queries/portfolioQuery.ts
|
|
2609
2765
|
var import_bignumber3 = __toESM(require("bignumber.js"));
|
|
@@ -3105,10 +3261,12 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
3105
3261
|
|
|
3106
3262
|
// src/queries/vescaQuery.ts
|
|
3107
3263
|
var import_bignumber4 = __toESM(require("bignumber.js"));
|
|
3264
|
+
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
3265
|
+
var import_bcs = require("@mysten/sui.js/bcs");
|
|
3108
3266
|
var getVescaKeys = async (query, ownerAddress) => {
|
|
3109
3267
|
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
3110
|
-
const
|
|
3111
|
-
const veScaKeyType = `${
|
|
3268
|
+
const veScaObjId = query.address.get("vesca.object");
|
|
3269
|
+
const veScaKeyType = `${veScaObjId}::ve_sca::VeScaKey`;
|
|
3112
3270
|
const keyObjectsResponse = [];
|
|
3113
3271
|
let hasNextPage = false;
|
|
3114
3272
|
let nextCursor = null;
|
|
@@ -3134,19 +3292,21 @@ var getVescaKeys = async (query, ownerAddress) => {
|
|
|
3134
3292
|
var getVeScas = async (query, ownerAddress) => {
|
|
3135
3293
|
const keyObjectDatas = await getVescaKeys(query, ownerAddress);
|
|
3136
3294
|
const keyObjectId = keyObjectDatas.map((data) => data.objectId);
|
|
3137
|
-
const veScas =
|
|
3138
|
-
|
|
3295
|
+
const veScas = Array(keyObjectId.length).fill(null);
|
|
3296
|
+
const tasks = keyObjectId.map(async (keyId, idx) => {
|
|
3139
3297
|
const veSca = await getVeSca(query, keyId);
|
|
3140
|
-
if (veSca)
|
|
3141
|
-
veScas
|
|
3142
|
-
|
|
3143
|
-
|
|
3298
|
+
if (veSca) {
|
|
3299
|
+
veScas[idx] = veSca;
|
|
3300
|
+
}
|
|
3301
|
+
});
|
|
3302
|
+
await Promise.allSettled(tasks);
|
|
3303
|
+
return veScas.filter(Boolean).sort((a, b) => a.currentVeScaBalance - b.currentVeScaBalance);
|
|
3144
3304
|
};
|
|
3145
3305
|
var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
3146
|
-
const tableId =
|
|
3306
|
+
const tableId = query.address.get(`vesca.tableId`);
|
|
3147
3307
|
veScaKeyId = veScaKeyId || (await getVescaKeys(query, ownerAddress))[0].objectId;
|
|
3148
3308
|
let vesca = void 0;
|
|
3149
|
-
const veScaDynamicFieldObjectResponse = await query.
|
|
3309
|
+
const veScaDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3150
3310
|
parentId: tableId,
|
|
3151
3311
|
name: {
|
|
3152
3312
|
type: "0x2::object::ID",
|
|
@@ -3174,11 +3334,79 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
|
3174
3334
|
}
|
|
3175
3335
|
return vesca;
|
|
3176
3336
|
};
|
|
3337
|
+
var getTotalVeScaTreasuryAmount = async (query) => {
|
|
3338
|
+
const veScaPkgId = query.address.get("vesca.id");
|
|
3339
|
+
const veScaConfig = query.address.get("vesca.config");
|
|
3340
|
+
const veScaTreasury = query.address.get("vesca.treasury");
|
|
3341
|
+
const refreshQueryTarget = `${veScaPkgId}::treasury::refresh`;
|
|
3342
|
+
const refreshArgs = [veScaConfig, veScaTreasury, import_sui_kit2.SUI_CLOCK_OBJECT_ID];
|
|
3343
|
+
const veScaAmountQueryTarget = `${veScaPkgId}::treasury::total_ve_sca_amount`;
|
|
3344
|
+
const veScaAmountArgs = [veScaTreasury, import_sui_kit2.SUI_CLOCK_OBJECT_ID];
|
|
3345
|
+
const resolvedRefreshArgs = await Promise.all(
|
|
3346
|
+
refreshArgs.map(async (arg) => {
|
|
3347
|
+
if (typeof arg === "string") {
|
|
3348
|
+
return (await query.cache.queryGetObject(arg, { showContent: true })).data;
|
|
3349
|
+
}
|
|
3350
|
+
return arg;
|
|
3351
|
+
})
|
|
3352
|
+
);
|
|
3353
|
+
const resolvedVeScaAmountArgs = await Promise.all(
|
|
3354
|
+
veScaAmountArgs.map(async (arg) => {
|
|
3355
|
+
if (typeof arg === "string") {
|
|
3356
|
+
return (await query.cache.queryGetObject(arg, { showContent: true })).data;
|
|
3357
|
+
}
|
|
3358
|
+
return arg;
|
|
3359
|
+
})
|
|
3360
|
+
);
|
|
3361
|
+
const txb = new import_sui_kit2.SuiTxBlock();
|
|
3362
|
+
txb.moveCall(refreshQueryTarget, resolvedRefreshArgs);
|
|
3363
|
+
txb.moveCall(veScaAmountQueryTarget, resolvedVeScaAmountArgs);
|
|
3364
|
+
const txBytes = await txb.txBlock.build({
|
|
3365
|
+
client: query.suiKit.client(),
|
|
3366
|
+
onlyTransactionKind: true,
|
|
3367
|
+
protocolConfig: await query.cache.getProtocolConfig()
|
|
3368
|
+
});
|
|
3369
|
+
const res = await query.cache.queryClient.fetchQuery({
|
|
3370
|
+
queryKey: [
|
|
3371
|
+
"getTotalVeScaTreasuryAmount",
|
|
3372
|
+
JSON.stringify([...refreshArgs, ...veScaAmountArgs])
|
|
3373
|
+
],
|
|
3374
|
+
queryFn: async () => {
|
|
3375
|
+
return await query.suiKit.inspectTxn(txBytes);
|
|
3376
|
+
},
|
|
3377
|
+
staleTime: 8e3
|
|
3378
|
+
});
|
|
3379
|
+
const results = res.results;
|
|
3380
|
+
if (results && results[1].returnValues) {
|
|
3381
|
+
const value = Uint8Array.from(results[1].returnValues[0][0]);
|
|
3382
|
+
const type = results[1].returnValues[0][1];
|
|
3383
|
+
return import_bcs.bcs.de(type, value);
|
|
3384
|
+
}
|
|
3385
|
+
return "0";
|
|
3386
|
+
};
|
|
3387
|
+
|
|
3388
|
+
// src/queries/referralQuery.ts
|
|
3389
|
+
var queryVeScaKeyIdFromReferralBindings = async (query, refereeAddress) => {
|
|
3390
|
+
const referralBindingTableId = query.address.get("referral.bindingTableId");
|
|
3391
|
+
const referralBindResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3392
|
+
parentId: referralBindingTableId,
|
|
3393
|
+
name: {
|
|
3394
|
+
type: "address",
|
|
3395
|
+
value: refereeAddress
|
|
3396
|
+
}
|
|
3397
|
+
});
|
|
3398
|
+
if (referralBindResponse.data?.content?.dataType !== "moveObject")
|
|
3399
|
+
return null;
|
|
3400
|
+
const fields = referralBindResponse.data.content.fields;
|
|
3401
|
+
return fields.value;
|
|
3402
|
+
};
|
|
3177
3403
|
|
|
3178
3404
|
// src/models/scallopIndexer.ts
|
|
3179
3405
|
var import_axios2 = __toESM(require("axios"));
|
|
3180
3406
|
var ScallopIndexer = class {
|
|
3181
|
-
constructor() {
|
|
3407
|
+
constructor(params, instance) {
|
|
3408
|
+
this.params = params;
|
|
3409
|
+
this._cache = instance?.cache ?? new ScallopCache();
|
|
3182
3410
|
this._requestClient = import_axios2.default.create({
|
|
3183
3411
|
baseURL: SDK_API_BASE_URL,
|
|
3184
3412
|
headers: {
|
|
@@ -3194,7 +3422,12 @@ var ScallopIndexer = class {
|
|
|
3194
3422
|
* @return Market data.
|
|
3195
3423
|
*/
|
|
3196
3424
|
async getMarket() {
|
|
3197
|
-
const response = await this.
|
|
3425
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
3426
|
+
queryKey: ["market"],
|
|
3427
|
+
queryFn: async () => {
|
|
3428
|
+
return await this._requestClient.get(`/api/market`);
|
|
3429
|
+
}
|
|
3430
|
+
});
|
|
3198
3431
|
if (response.status === 200) {
|
|
3199
3432
|
return {
|
|
3200
3433
|
pools: response.data.pools.reduce((marketPools, marketPool) => {
|
|
@@ -3219,15 +3452,8 @@ var ScallopIndexer = class {
|
|
|
3219
3452
|
* @return Market pools data.
|
|
3220
3453
|
*/
|
|
3221
3454
|
async getMarketPools() {
|
|
3222
|
-
const response = await this.
|
|
3223
|
-
|
|
3224
|
-
return response.data.pools.reduce((marketPools, marketPool) => {
|
|
3225
|
-
marketPools[marketPool.coinName] = marketPool;
|
|
3226
|
-
return marketPools;
|
|
3227
|
-
}, {});
|
|
3228
|
-
} else {
|
|
3229
|
-
throw Error("Failed to getMarketPools.");
|
|
3230
|
-
}
|
|
3455
|
+
const response = (await this.getMarket()).pools;
|
|
3456
|
+
return response;
|
|
3231
3457
|
}
|
|
3232
3458
|
/**
|
|
3233
3459
|
* Get market pool index data.
|
|
@@ -3235,12 +3461,7 @@ var ScallopIndexer = class {
|
|
|
3235
3461
|
* @return Market pool data.
|
|
3236
3462
|
*/
|
|
3237
3463
|
async getMarketPool(poolCoinName) {
|
|
3238
|
-
|
|
3239
|
-
if (response.status === 200) {
|
|
3240
|
-
return response.data.pool;
|
|
3241
|
-
} else {
|
|
3242
|
-
throw Error("Failed to getMarketPool.");
|
|
3243
|
-
}
|
|
3464
|
+
return (await this.getMarketPools())[poolCoinName];
|
|
3244
3465
|
}
|
|
3245
3466
|
/**
|
|
3246
3467
|
* Get market collaterals index data.
|
|
@@ -3248,18 +3469,7 @@ var ScallopIndexer = class {
|
|
|
3248
3469
|
* @return Market collaterals data.
|
|
3249
3470
|
*/
|
|
3250
3471
|
async getMarketCollaterals() {
|
|
3251
|
-
|
|
3252
|
-
if (response.status === 200) {
|
|
3253
|
-
return response.data.collaterals.reduce(
|
|
3254
|
-
(marketCollaterals, marketCollateral) => {
|
|
3255
|
-
marketCollaterals[marketCollateral.coinName] = marketCollateral;
|
|
3256
|
-
return marketCollaterals;
|
|
3257
|
-
},
|
|
3258
|
-
{}
|
|
3259
|
-
);
|
|
3260
|
-
} else {
|
|
3261
|
-
throw Error("Failed to getMarketCollaterals.");
|
|
3262
|
-
}
|
|
3472
|
+
return (await this.getMarket()).collaterals;
|
|
3263
3473
|
}
|
|
3264
3474
|
/**
|
|
3265
3475
|
* Get market collateral index data.
|
|
@@ -3267,12 +3477,7 @@ var ScallopIndexer = class {
|
|
|
3267
3477
|
* @return Market collateral data.
|
|
3268
3478
|
*/
|
|
3269
3479
|
async getMarketCollateral(collateralCoinName) {
|
|
3270
|
-
|
|
3271
|
-
if (response.status === 200) {
|
|
3272
|
-
return response.data.collateral;
|
|
3273
|
-
} else {
|
|
3274
|
-
throw Error("Failed to getMarketCollateral.");
|
|
3275
|
-
}
|
|
3480
|
+
return (await this.getMarketCollaterals())[collateralCoinName];
|
|
3276
3481
|
}
|
|
3277
3482
|
/**
|
|
3278
3483
|
* Get spools index data.
|
|
@@ -3280,7 +3485,12 @@ var ScallopIndexer = class {
|
|
|
3280
3485
|
* @return Spools data.
|
|
3281
3486
|
*/
|
|
3282
3487
|
async getSpools() {
|
|
3283
|
-
const response = await this.
|
|
3488
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
3489
|
+
queryKey: ["spools"],
|
|
3490
|
+
queryFn: async () => {
|
|
3491
|
+
return await this._requestClient.get(`/api/spools`);
|
|
3492
|
+
}
|
|
3493
|
+
});
|
|
3284
3494
|
if (response.status === 200) {
|
|
3285
3495
|
return response.data.spools.reduce((spools, spool) => {
|
|
3286
3496
|
spools[spool.marketCoinName] = spool;
|
|
@@ -3296,12 +3506,7 @@ var ScallopIndexer = class {
|
|
|
3296
3506
|
* @return Spool data.
|
|
3297
3507
|
*/
|
|
3298
3508
|
async getSpool(marketCoinName) {
|
|
3299
|
-
|
|
3300
|
-
if (response.status === 200) {
|
|
3301
|
-
return response.data.spool;
|
|
3302
|
-
} else {
|
|
3303
|
-
throw Error("Failed to getSpool.");
|
|
3304
|
-
}
|
|
3509
|
+
return (await this.getSpools())[marketCoinName];
|
|
3305
3510
|
}
|
|
3306
3511
|
/**
|
|
3307
3512
|
* Get borrow incentive pools index data.
|
|
@@ -3309,7 +3514,12 @@ var ScallopIndexer = class {
|
|
|
3309
3514
|
* @return Borrow incentive pools data.
|
|
3310
3515
|
*/
|
|
3311
3516
|
async getBorrowIncentivePools() {
|
|
3312
|
-
const response = await this.
|
|
3517
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
3518
|
+
queryKey: ["borrowIncentivePools"],
|
|
3519
|
+
queryFn: async () => {
|
|
3520
|
+
return await this._requestClient.get(`/api/borrowIncentivePools`);
|
|
3521
|
+
}
|
|
3522
|
+
});
|
|
3313
3523
|
if (response.status === 200) {
|
|
3314
3524
|
return response.data.borrowIncentivePools.reduce(
|
|
3315
3525
|
(borrowIncentivePools, borrowIncentivePool) => {
|
|
@@ -3328,14 +3538,7 @@ var ScallopIndexer = class {
|
|
|
3328
3538
|
* @return Borrow incentive pool data.
|
|
3329
3539
|
*/
|
|
3330
3540
|
async getBorrowIncentivePool(borrowIncentiveCoinName) {
|
|
3331
|
-
|
|
3332
|
-
`${SDK_API_BASE_URL}/api/borrowIncentivePool/${borrowIncentiveCoinName}`
|
|
3333
|
-
);
|
|
3334
|
-
if (response.status === 200) {
|
|
3335
|
-
return response.data.borrowIncentivePool;
|
|
3336
|
-
} else {
|
|
3337
|
-
throw Error("Failed to getSpool.");
|
|
3338
|
-
}
|
|
3541
|
+
return (await this.getBorrowIncentivePools())[borrowIncentiveCoinName];
|
|
3339
3542
|
}
|
|
3340
3543
|
/**
|
|
3341
3544
|
* Get total value locked index data.
|
|
@@ -3343,7 +3546,12 @@ var ScallopIndexer = class {
|
|
|
3343
3546
|
* @return Total value locked.
|
|
3344
3547
|
*/
|
|
3345
3548
|
async getTotalValueLocked() {
|
|
3346
|
-
const response = await this.
|
|
3549
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
3550
|
+
queryKey: ["totalValueLocked"],
|
|
3551
|
+
queryFn: async () => {
|
|
3552
|
+
return await this._requestClient.get(`/api/market/tvl`);
|
|
3553
|
+
}
|
|
3554
|
+
});
|
|
3347
3555
|
if (response.status === 200) {
|
|
3348
3556
|
return response.data;
|
|
3349
3557
|
} else {
|
|
@@ -3357,16 +3565,21 @@ var ScallopQuery = class {
|
|
|
3357
3565
|
constructor(params, instance) {
|
|
3358
3566
|
this.params = params;
|
|
3359
3567
|
this.suiKit = instance?.suiKit ?? new import_sui_kit3.SuiKit(params);
|
|
3360
|
-
this.
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3568
|
+
this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
|
|
3569
|
+
this.address = instance?.address ?? new ScallopAddress(
|
|
3570
|
+
{
|
|
3571
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
3572
|
+
network: params?.networkType
|
|
3573
|
+
},
|
|
3574
|
+
this.cache
|
|
3575
|
+
);
|
|
3364
3576
|
this.utils = instance?.utils ?? new ScallopUtils(this.params, {
|
|
3365
3577
|
suiKit: this.suiKit,
|
|
3366
3578
|
address: this.address,
|
|
3579
|
+
cache: this.cache,
|
|
3367
3580
|
query: this
|
|
3368
3581
|
});
|
|
3369
|
-
this.indexer = new ScallopIndexer();
|
|
3582
|
+
this.indexer = new ScallopIndexer(this.params, { cache: this.cache });
|
|
3370
3583
|
}
|
|
3371
3584
|
/**
|
|
3372
3585
|
* Request the scallop API to initialize data.
|
|
@@ -3506,6 +3719,15 @@ var ScallopQuery = class {
|
|
|
3506
3719
|
async getPriceFromPyth(assetCoinName) {
|
|
3507
3720
|
return await getPythPrice(this, assetCoinName);
|
|
3508
3721
|
}
|
|
3722
|
+
/**
|
|
3723
|
+
* Get prices from pyth fee object.
|
|
3724
|
+
*
|
|
3725
|
+
* @param assetCoinNames - Array of supported asset coin names.
|
|
3726
|
+
* @return Array of asset coin prices.
|
|
3727
|
+
*/
|
|
3728
|
+
async getPricesFromPyth(assetCoinNames) {
|
|
3729
|
+
return await getPythPrices(this, assetCoinNames);
|
|
3730
|
+
}
|
|
3509
3731
|
/* ==================== Spool Query Methods ==================== */
|
|
3510
3732
|
/**
|
|
3511
3733
|
* Get spools data.
|
|
@@ -3704,6 +3926,29 @@ var ScallopQuery = class {
|
|
|
3704
3926
|
async getTvl(indexer = false) {
|
|
3705
3927
|
return await getTotalValueLocked(this, indexer);
|
|
3706
3928
|
}
|
|
3929
|
+
/**
|
|
3930
|
+
* Get all veSca from walletAdddress
|
|
3931
|
+
* @param walletAddress
|
|
3932
|
+
* @returns array of veSca
|
|
3933
|
+
*/
|
|
3934
|
+
async getVeScas(walletAddress) {
|
|
3935
|
+
return await getVeScas(this, walletAddress);
|
|
3936
|
+
}
|
|
3937
|
+
/**
|
|
3938
|
+
* Get total vesca treasury with movecall
|
|
3939
|
+
* @returns Promise<string | undefined>
|
|
3940
|
+
*/
|
|
3941
|
+
async getTotalVeScaTreasuryAmount() {
|
|
3942
|
+
return await getTotalVeScaTreasuryAmount(this);
|
|
3943
|
+
}
|
|
3944
|
+
/**
|
|
3945
|
+
* Return binded veScaKeyId of walletAddress if exist
|
|
3946
|
+
* @param walletAddress
|
|
3947
|
+
* @returns veScaKeyId
|
|
3948
|
+
*/
|
|
3949
|
+
async getVeScaKeyIdFromReferralBindings(walletAddress) {
|
|
3950
|
+
return await queryVeScaKeyIdFromReferralBindings(this, walletAddress);
|
|
3951
|
+
}
|
|
3707
3952
|
/**
|
|
3708
3953
|
* Get binded obligationId from a veScaKey if it exists.
|
|
3709
3954
|
* @param veScaKey
|
|
@@ -3752,13 +3997,18 @@ var ScallopUtils = class {
|
|
|
3752
3997
|
};
|
|
3753
3998
|
this.params = params;
|
|
3754
3999
|
this._suiKit = instance?.suiKit ?? new import_sui_kit4.SuiKit(params);
|
|
3755
|
-
this.
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
4000
|
+
this._cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this._suiKit);
|
|
4001
|
+
this._address = instance?.address ?? new ScallopAddress(
|
|
4002
|
+
{
|
|
4003
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
4004
|
+
network: params?.networkType
|
|
4005
|
+
},
|
|
4006
|
+
this._cache
|
|
4007
|
+
);
|
|
3759
4008
|
this._query = instance?.query ?? new ScallopQuery(params, {
|
|
3760
4009
|
suiKit: this._suiKit,
|
|
3761
|
-
address: this._address
|
|
4010
|
+
address: this._address,
|
|
4011
|
+
cache: this._cache
|
|
3762
4012
|
});
|
|
3763
4013
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
3764
4014
|
}
|
|
@@ -3975,40 +4225,60 @@ var ScallopUtils = class {
|
|
|
3975
4225
|
}
|
|
3976
4226
|
if (lackPricesCoinNames.length > 0) {
|
|
3977
4227
|
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
4228
|
+
const failedRequests = new Set(
|
|
4229
|
+
lackPricesCoinNames
|
|
4230
|
+
);
|
|
4231
|
+
for (const endpoint of endpoints) {
|
|
4232
|
+
const priceIds = Array.from(failedRequests.values()).reduce(
|
|
4233
|
+
(acc, coinName) => {
|
|
4234
|
+
const priceId = this._address.get(
|
|
4235
|
+
`core.coins.${coinName}.oracle.pyth.feed`
|
|
3984
4236
|
);
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
4237
|
+
acc[coinName] = priceId;
|
|
4238
|
+
return acc;
|
|
4239
|
+
},
|
|
4240
|
+
{}
|
|
4241
|
+
);
|
|
4242
|
+
await Promise.allSettled(
|
|
4243
|
+
Object.entries(priceIds).map(async ([coinName, priceId]) => {
|
|
4244
|
+
const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint);
|
|
4245
|
+
try {
|
|
4246
|
+
const feed = await this._cache.queryClient.fetchQuery({
|
|
4247
|
+
queryKey: [priceId],
|
|
4248
|
+
queryFn: async () => {
|
|
4249
|
+
return await pythConnection.getLatestPriceFeeds([priceId]);
|
|
4250
|
+
}
|
|
3992
4251
|
});
|
|
3993
|
-
|
|
4252
|
+
if (feed) {
|
|
4253
|
+
const data = parseDataFromPythPriceFeed(feed[0], this._address);
|
|
4254
|
+
this._priceMap.set(coinName, {
|
|
4255
|
+
price: data.price,
|
|
4256
|
+
publishTime: data.publishTime
|
|
4257
|
+
});
|
|
4258
|
+
coinPrices[coinName] = data.price;
|
|
4259
|
+
}
|
|
4260
|
+
failedRequests.delete(coinName);
|
|
4261
|
+
} catch (e) {
|
|
4262
|
+
console.warn(
|
|
4263
|
+
`Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
|
|
4264
|
+
);
|
|
3994
4265
|
}
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
})
|
|
4010
|
-
|
|
4011
|
-
}
|
|
4266
|
+
})
|
|
4267
|
+
);
|
|
4268
|
+
if (failedRequests.size === 0)
|
|
4269
|
+
break;
|
|
4270
|
+
}
|
|
4271
|
+
if (failedRequests.size > 0) {
|
|
4272
|
+
await Promise.allSettled(
|
|
4273
|
+
Array.from(failedRequests.values()).map(async (coinName) => {
|
|
4274
|
+
const price = await this._query.getPriceFromPyth(coinName);
|
|
4275
|
+
this._priceMap.set(coinName, {
|
|
4276
|
+
price,
|
|
4277
|
+
publishTime: Date.now()
|
|
4278
|
+
});
|
|
4279
|
+
coinPrices[coinName] = price;
|
|
4280
|
+
})
|
|
4281
|
+
);
|
|
4012
4282
|
}
|
|
4013
4283
|
}
|
|
4014
4284
|
return coinPrices;
|
|
@@ -4068,8 +4338,8 @@ var ScallopUtils = class {
|
|
|
4068
4338
|
};
|
|
4069
4339
|
|
|
4070
4340
|
// src/models/scallopBuilder.ts
|
|
4071
|
-
var
|
|
4072
|
-
var
|
|
4341
|
+
var import_utils20 = require("@mysten/sui.js/utils");
|
|
4342
|
+
var import_sui_kit10 = require("@scallop-io/sui-kit");
|
|
4073
4343
|
|
|
4074
4344
|
// src/builders/coreBuilder.ts
|
|
4075
4345
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
@@ -4244,6 +4514,8 @@ var generateCoreNormalMethod = ({
|
|
|
4244
4514
|
coinDecimalsRegistry: builder.address.get("core.coinDecimalsRegistry"),
|
|
4245
4515
|
xOracle: builder.address.get("core.oracles.xOracle")
|
|
4246
4516
|
};
|
|
4517
|
+
const referralPkgId = builder.address.get("referral.id");
|
|
4518
|
+
const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
|
|
4247
4519
|
return {
|
|
4248
4520
|
openObligation: () => txBlock.moveCall(
|
|
4249
4521
|
`${coreIds.protocolPkg}::open_obligation::open_obligation`,
|
|
@@ -4331,6 +4603,24 @@ var generateCoreNormalMethod = ({
|
|
|
4331
4603
|
[coinType]
|
|
4332
4604
|
);
|
|
4333
4605
|
},
|
|
4606
|
+
borrowWithReferral: (obligation, obligationKey, borrowReferral, amount, poolCoinName) => {
|
|
4607
|
+
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
4608
|
+
return txBlock.moveCall(
|
|
4609
|
+
`${coreIds.protocolPkg}::borrow::borrow_with_referral`,
|
|
4610
|
+
[
|
|
4611
|
+
coreIds.version,
|
|
4612
|
+
obligation,
|
|
4613
|
+
obligationKey,
|
|
4614
|
+
coreIds.market,
|
|
4615
|
+
coreIds.coinDecimalsRegistry,
|
|
4616
|
+
borrowReferral,
|
|
4617
|
+
amount,
|
|
4618
|
+
coreIds.xOracle,
|
|
4619
|
+
import_utils12.SUI_CLOCK_OBJECT_ID
|
|
4620
|
+
],
|
|
4621
|
+
[coinType, referralWitnessType]
|
|
4622
|
+
);
|
|
4623
|
+
},
|
|
4334
4624
|
borrowEntry: (obligation, obligationKey, amount, poolCoinName) => {
|
|
4335
4625
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
4336
4626
|
return txBlock.moveCall(
|
|
@@ -4471,6 +4761,26 @@ var generateCoreQuickMethod = ({
|
|
|
4471
4761
|
poolCoinName
|
|
4472
4762
|
);
|
|
4473
4763
|
},
|
|
4764
|
+
borrowWithReferralQuick: async (amount, poolCoinName, borrowReferral, obligationId, obligationKey) => {
|
|
4765
|
+
const obligationInfo = await requireObligationInfo(
|
|
4766
|
+
builder,
|
|
4767
|
+
txBlock,
|
|
4768
|
+
obligationId,
|
|
4769
|
+
obligationKey
|
|
4770
|
+
);
|
|
4771
|
+
const obligationCoinNames = await builder.utils.getObligationCoinNames(
|
|
4772
|
+
obligationInfo.obligationId
|
|
4773
|
+
);
|
|
4774
|
+
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
4775
|
+
await updateOracles(builder, txBlock, updateCoinNames);
|
|
4776
|
+
return txBlock.borrowWithReferral(
|
|
4777
|
+
obligationInfo.obligationId,
|
|
4778
|
+
obligationInfo.obligationKey,
|
|
4779
|
+
borrowReferral,
|
|
4780
|
+
amount,
|
|
4781
|
+
poolCoinName
|
|
4782
|
+
);
|
|
4783
|
+
},
|
|
4474
4784
|
repayQuick: async (amount, poolCoinName, obligationId) => {
|
|
4475
4785
|
const sender = requireSender(txBlock);
|
|
4476
4786
|
const obligationInfo = await requireObligationInfo(
|
|
@@ -4742,10 +5052,7 @@ var requireVeSca = async (...params) => {
|
|
|
4742
5052
|
if (veScas.length === 0) {
|
|
4743
5053
|
return void 0;
|
|
4744
5054
|
}
|
|
4745
|
-
return veScas
|
|
4746
|
-
(prev, acc) => acc.currentVeScaBalance > prev.currentVeScaBalance ? acc : prev,
|
|
4747
|
-
veScas[0]
|
|
4748
|
-
);
|
|
5055
|
+
return veScas[0];
|
|
4749
5056
|
};
|
|
4750
5057
|
var generateNormalVeScaMethod = ({
|
|
4751
5058
|
builder,
|
|
@@ -4827,6 +5134,13 @@ var generateNormalVeScaMethod = ({
|
|
|
4827
5134
|
],
|
|
4828
5135
|
[]
|
|
4829
5136
|
);
|
|
5137
|
+
},
|
|
5138
|
+
mintEmptyVeSca: () => {
|
|
5139
|
+
return txBlock.moveCall(
|
|
5140
|
+
`${veScaIds.pkgId}::ve_sca::mint_ve_sca_placeholder_key`,
|
|
5141
|
+
[veScaIds.config, veScaIds.table],
|
|
5142
|
+
[]
|
|
5143
|
+
);
|
|
4830
5144
|
}
|
|
4831
5145
|
};
|
|
4832
5146
|
};
|
|
@@ -5022,7 +5336,7 @@ var requireObligationInfo2 = async (...params) => {
|
|
|
5022
5336
|
};
|
|
5023
5337
|
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
5024
5338
|
const borrowIncentiveIds = {
|
|
5025
|
-
borrowIncentivePkg:
|
|
5339
|
+
borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
|
|
5026
5340
|
query: builder.address.get("borrowIncentive.query"),
|
|
5027
5341
|
config: builder.address.get("borrowIncentive.config"),
|
|
5028
5342
|
incentivePools: builder.address.get("borrowIncentive.incentivePools"),
|
|
@@ -5084,7 +5398,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
5084
5398
|
);
|
|
5085
5399
|
},
|
|
5086
5400
|
claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
|
|
5087
|
-
const rewardCoinNames =
|
|
5401
|
+
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
5088
5402
|
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
5089
5403
|
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
5090
5404
|
}
|
|
@@ -5131,9 +5445,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
5131
5445
|
obligationKey
|
|
5132
5446
|
);
|
|
5133
5447
|
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5134
|
-
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target ===
|
|
5135
|
-
"borrowIncentive.id"
|
|
5136
|
-
)}::user::unstake`))
|
|
5448
|
+
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5137
5449
|
);
|
|
5138
5450
|
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5139
5451
|
txBlock.stakeObligation(obligationArg, obligationtKeyArg);
|
|
@@ -5151,9 +5463,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
5151
5463
|
obligationKey
|
|
5152
5464
|
);
|
|
5153
5465
|
const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
|
|
5154
|
-
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target ===
|
|
5155
|
-
"borrowIncentive.id"
|
|
5156
|
-
)}::user::unstake`))
|
|
5466
|
+
(txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
|
|
5157
5467
|
);
|
|
5158
5468
|
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
5159
5469
|
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
@@ -5162,7 +5472,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
5162
5472
|
builder.query,
|
|
5163
5473
|
veSca.keyId
|
|
5164
5474
|
);
|
|
5165
|
-
if (!bindedObligationId || bindedObligationId === obligationArg) {
|
|
5475
|
+
if ((!bindedObligationId || bindedObligationId === obligationArg) && veSca.currentVeScaBalance > 0) {
|
|
5166
5476
|
txBlock.stakeObligationWithVesca(
|
|
5167
5477
|
obligationArg,
|
|
5168
5478
|
obligationtKeyArg,
|
|
@@ -5238,6 +5548,138 @@ var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
|
|
|
5238
5548
|
});
|
|
5239
5549
|
};
|
|
5240
5550
|
|
|
5551
|
+
// src/builders/referralBuilder.ts
|
|
5552
|
+
var import_sui_kit9 = require("@scallop-io/sui-kit");
|
|
5553
|
+
var generateReferralNormalMethod = ({
|
|
5554
|
+
builder,
|
|
5555
|
+
txBlock
|
|
5556
|
+
}) => {
|
|
5557
|
+
const referralIds = {
|
|
5558
|
+
referralPgkId: builder.address.get("referral.id"),
|
|
5559
|
+
referralBindings: builder.address.get("referral.referralBindings"),
|
|
5560
|
+
referralRevenuePool: builder.address.get("referral.referralRevenuePool"),
|
|
5561
|
+
authorizedWitnessList: builder.address.get(
|
|
5562
|
+
"referral.authorizedWitnessList"
|
|
5563
|
+
),
|
|
5564
|
+
referralTiers: builder.address.get("referral.referralTiers"),
|
|
5565
|
+
version: builder.address.get("referral.version")
|
|
5566
|
+
};
|
|
5567
|
+
const veScaTable = builder.address.get("vesca.table");
|
|
5568
|
+
return {
|
|
5569
|
+
bindToReferral: (veScaKeyId) => {
|
|
5570
|
+
return txBlock.moveCall(
|
|
5571
|
+
`${referralIds.referralPgkId}::referral_bindings::bind_ve_sca_referrer`,
|
|
5572
|
+
[
|
|
5573
|
+
referralIds.referralBindings,
|
|
5574
|
+
txBlock.pure(veScaKeyId),
|
|
5575
|
+
veScaTable,
|
|
5576
|
+
import_sui_kit9.SUI_CLOCK_OBJECT_ID
|
|
5577
|
+
],
|
|
5578
|
+
[]
|
|
5579
|
+
);
|
|
5580
|
+
},
|
|
5581
|
+
claimReferralTicket: (poolCoinName) => {
|
|
5582
|
+
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
5583
|
+
return txBlock.moveCall(
|
|
5584
|
+
`${referralIds.referralPgkId}::scallop_referral_program::claim_ve_sca_referral_ticket`,
|
|
5585
|
+
[
|
|
5586
|
+
referralIds.version,
|
|
5587
|
+
veScaTable,
|
|
5588
|
+
referralIds.referralBindings,
|
|
5589
|
+
referralIds.authorizedWitnessList,
|
|
5590
|
+
referralIds.referralTiers,
|
|
5591
|
+
import_sui_kit9.SUI_CLOCK_OBJECT_ID
|
|
5592
|
+
],
|
|
5593
|
+
[coinType]
|
|
5594
|
+
);
|
|
5595
|
+
},
|
|
5596
|
+
burnReferralTicket: (ticket, poolCoinName) => {
|
|
5597
|
+
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
5598
|
+
return txBlock.moveCall(
|
|
5599
|
+
`${referralIds.referralPgkId}::scallop_referral_program::burn_ve_sca_referral_ticket`,
|
|
5600
|
+
[
|
|
5601
|
+
referralIds.version,
|
|
5602
|
+
ticket,
|
|
5603
|
+
referralIds.referralRevenuePool,
|
|
5604
|
+
import_sui_kit9.SUI_CLOCK_OBJECT_ID
|
|
5605
|
+
],
|
|
5606
|
+
[coinType]
|
|
5607
|
+
);
|
|
5608
|
+
},
|
|
5609
|
+
claimReferralRevenue: (veScaKey, poolCoinName) => {
|
|
5610
|
+
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
5611
|
+
return txBlock.moveCall(
|
|
5612
|
+
`${referralIds.referralPgkId}::referral_revenue_pool::claim_revenue_with_ve_sca_key`,
|
|
5613
|
+
[
|
|
5614
|
+
referralIds.version,
|
|
5615
|
+
referralIds.referralRevenuePool,
|
|
5616
|
+
veScaKey,
|
|
5617
|
+
import_sui_kit9.SUI_CLOCK_OBJECT_ID
|
|
5618
|
+
],
|
|
5619
|
+
[coinType]
|
|
5620
|
+
);
|
|
5621
|
+
}
|
|
5622
|
+
};
|
|
5623
|
+
};
|
|
5624
|
+
var generateReferralQuickMethod = ({
|
|
5625
|
+
builder,
|
|
5626
|
+
txBlock
|
|
5627
|
+
}) => {
|
|
5628
|
+
return {
|
|
5629
|
+
claimReferralRevenueQuick: async (veScaKey, coinNames = [...SUPPORT_POOLS]) => {
|
|
5630
|
+
const sender = requireSender(txBlock);
|
|
5631
|
+
const objToTransfer = [];
|
|
5632
|
+
for (const coinName of coinNames) {
|
|
5633
|
+
if (coinName === "sui") {
|
|
5634
|
+
const rewardCoin = txBlock.claimReferralRevenue(veScaKey, coinName);
|
|
5635
|
+
objToTransfer.push(rewardCoin);
|
|
5636
|
+
} else {
|
|
5637
|
+
const coins = await builder.suiKit.suiInteractor.selectCoins(
|
|
5638
|
+
sender,
|
|
5639
|
+
Infinity,
|
|
5640
|
+
builder.utils.parseCoinType(coinName)
|
|
5641
|
+
);
|
|
5642
|
+
const rewardCoin = txBlock.claimReferralRevenue(veScaKey, coinName);
|
|
5643
|
+
if (coins.length > 0) {
|
|
5644
|
+
txBlock.mergeCoins(rewardCoin, coins);
|
|
5645
|
+
}
|
|
5646
|
+
objToTransfer.push(rewardCoin);
|
|
5647
|
+
}
|
|
5648
|
+
}
|
|
5649
|
+
if (objToTransfer.length > 0) {
|
|
5650
|
+
txBlock.transferObjects(objToTransfer, sender);
|
|
5651
|
+
}
|
|
5652
|
+
}
|
|
5653
|
+
};
|
|
5654
|
+
};
|
|
5655
|
+
var newReferralTxBlock = (builder, initTxBlock) => {
|
|
5656
|
+
const txBlock = initTxBlock instanceof import_sui_kit9.TransactionBlock ? new import_sui_kit9.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit9.SuiTxBlock();
|
|
5657
|
+
const normalMethod = generateReferralNormalMethod({
|
|
5658
|
+
builder,
|
|
5659
|
+
txBlock
|
|
5660
|
+
});
|
|
5661
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
5662
|
+
get: (target, prop) => {
|
|
5663
|
+
if (prop in normalMethod) {
|
|
5664
|
+
return Reflect.get(normalMethod, prop);
|
|
5665
|
+
}
|
|
5666
|
+
return Reflect.get(target, prop);
|
|
5667
|
+
}
|
|
5668
|
+
});
|
|
5669
|
+
const quickMethod = generateReferralQuickMethod({
|
|
5670
|
+
builder,
|
|
5671
|
+
txBlock: normalTxBlock
|
|
5672
|
+
});
|
|
5673
|
+
return new Proxy(normalTxBlock, {
|
|
5674
|
+
get: (target, prop) => {
|
|
5675
|
+
if (prop in quickMethod) {
|
|
5676
|
+
return Reflect.get(quickMethod, prop);
|
|
5677
|
+
}
|
|
5678
|
+
return Reflect.get(target, prop);
|
|
5679
|
+
}
|
|
5680
|
+
});
|
|
5681
|
+
};
|
|
5682
|
+
|
|
5241
5683
|
// src/builders/index.ts
|
|
5242
5684
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
5243
5685
|
const vescaTxBlock = newVeScaTxBlock(builder, initTxBlock);
|
|
@@ -5245,7 +5687,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
5245
5687
|
builder,
|
|
5246
5688
|
vescaTxBlock
|
|
5247
5689
|
);
|
|
5248
|
-
const
|
|
5690
|
+
const referralTxBlock = newReferralTxBlock(builder, borrowIncentiveTxBlock);
|
|
5691
|
+
const spoolTxBlock = newSpoolTxBlock(builder, referralTxBlock);
|
|
5249
5692
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
5250
5693
|
return new Proxy(coreTxBlock, {
|
|
5251
5694
|
get: (target, prop) => {
|
|
@@ -5253,6 +5696,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
5253
5696
|
return Reflect.get(vescaTxBlock, prop);
|
|
5254
5697
|
} else if (prop in borrowIncentiveTxBlock) {
|
|
5255
5698
|
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
5699
|
+
} else if (prop in referralTxBlock) {
|
|
5700
|
+
return Reflect.get(referralTxBlock, prop);
|
|
5256
5701
|
} else if (prop in spoolTxBlock) {
|
|
5257
5702
|
return Reflect.get(spoolTxBlock, prop);
|
|
5258
5703
|
}
|
|
@@ -5265,21 +5710,27 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
5265
5710
|
var ScallopBuilder = class {
|
|
5266
5711
|
constructor(params, instance) {
|
|
5267
5712
|
this.params = params;
|
|
5268
|
-
this.suiKit = instance?.suiKit ?? new
|
|
5269
|
-
this.
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5713
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit10.SuiKit(params);
|
|
5714
|
+
this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
|
|
5715
|
+
this.address = instance?.address ?? new ScallopAddress(
|
|
5716
|
+
{
|
|
5717
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
5718
|
+
network: params?.networkType
|
|
5719
|
+
},
|
|
5720
|
+
this.cache
|
|
5721
|
+
);
|
|
5273
5722
|
this.query = instance?.query ?? new ScallopQuery(params, {
|
|
5274
5723
|
suiKit: this.suiKit,
|
|
5275
|
-
address: this.address
|
|
5724
|
+
address: this.address,
|
|
5725
|
+
cache: this.cache
|
|
5276
5726
|
});
|
|
5277
5727
|
this.utils = instance?.utils ?? new ScallopUtils(this.params, {
|
|
5278
5728
|
suiKit: this.suiKit,
|
|
5279
5729
|
address: this.address,
|
|
5280
|
-
query: this.query
|
|
5730
|
+
query: this.query,
|
|
5731
|
+
cache: this.cache
|
|
5281
5732
|
});
|
|
5282
|
-
this.walletAddress = (0,
|
|
5733
|
+
this.walletAddress = (0, import_utils20.normalizeSuiAddress)(
|
|
5283
5734
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
5284
5735
|
);
|
|
5285
5736
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -5358,27 +5809,34 @@ var ScallopBuilder = class {
|
|
|
5358
5809
|
var ScallopClient = class {
|
|
5359
5810
|
constructor(params, instance) {
|
|
5360
5811
|
this.params = params;
|
|
5361
|
-
this.suiKit = instance?.suiKit ?? new
|
|
5362
|
-
this.
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5812
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit11.SuiKit(params);
|
|
5813
|
+
this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
|
|
5814
|
+
this.address = instance?.address ?? new ScallopAddress(
|
|
5815
|
+
{
|
|
5816
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
5817
|
+
network: params?.networkType
|
|
5818
|
+
},
|
|
5819
|
+
this.cache
|
|
5820
|
+
);
|
|
5366
5821
|
this.query = instance?.query ?? new ScallopQuery(params, {
|
|
5367
5822
|
suiKit: this.suiKit,
|
|
5368
|
-
address: this.address
|
|
5823
|
+
address: this.address,
|
|
5824
|
+
cache: this.cache
|
|
5369
5825
|
});
|
|
5370
5826
|
this.utils = instance?.utils ?? new ScallopUtils(params, {
|
|
5371
5827
|
suiKit: this.suiKit,
|
|
5372
5828
|
address: this.address,
|
|
5373
|
-
query: this.query
|
|
5829
|
+
query: this.query,
|
|
5830
|
+
cache: this.cache
|
|
5374
5831
|
});
|
|
5375
5832
|
this.builder = instance?.builder ?? new ScallopBuilder(params, {
|
|
5376
5833
|
suiKit: this.suiKit,
|
|
5377
5834
|
address: this.address,
|
|
5378
5835
|
query: this.query,
|
|
5379
|
-
utils: this.utils
|
|
5836
|
+
utils: this.utils,
|
|
5837
|
+
cache: this.cache
|
|
5380
5838
|
});
|
|
5381
|
-
this.walletAddress = (0,
|
|
5839
|
+
this.walletAddress = (0, import_utils21.normalizeSuiAddress)(
|
|
5382
5840
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
5383
5841
|
);
|
|
5384
5842
|
}
|
|
@@ -5882,13 +6340,20 @@ var ScallopClient = class {
|
|
|
5882
6340
|
|
|
5883
6341
|
// src/models/scallop.ts
|
|
5884
6342
|
var Scallop = class {
|
|
5885
|
-
constructor(params) {
|
|
6343
|
+
constructor(params, cacheOptions) {
|
|
5886
6344
|
this.params = params;
|
|
5887
|
-
this.suiKit = new
|
|
5888
|
-
this.
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
6345
|
+
this.suiKit = new import_sui_kit12.SuiKit(params);
|
|
6346
|
+
this.cache = new ScallopCache(
|
|
6347
|
+
cacheOptions ?? DEFAULT_CACHE_OPTIONS,
|
|
6348
|
+
this.suiKit
|
|
6349
|
+
);
|
|
6350
|
+
this._address = new ScallopAddress(
|
|
6351
|
+
{
|
|
6352
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
6353
|
+
network: params?.networkType
|
|
6354
|
+
},
|
|
6355
|
+
this.cache
|
|
6356
|
+
);
|
|
5892
6357
|
}
|
|
5893
6358
|
/**
|
|
5894
6359
|
* Get a scallop address instance that already has read addresses.
|
|
@@ -5910,7 +6375,8 @@ var Scallop = class {
|
|
|
5910
6375
|
await this._address.read();
|
|
5911
6376
|
const scallopBuilder = new ScallopBuilder(this.params, {
|
|
5912
6377
|
suiKit: this.suiKit,
|
|
5913
|
-
address: this._address
|
|
6378
|
+
address: this._address,
|
|
6379
|
+
cache: this.cache
|
|
5914
6380
|
});
|
|
5915
6381
|
return scallopBuilder;
|
|
5916
6382
|
}
|
|
@@ -5925,7 +6391,7 @@ var Scallop = class {
|
|
|
5925
6391
|
await this._address.read();
|
|
5926
6392
|
const scallopClient = new ScallopClient(
|
|
5927
6393
|
{ ...this.params, walletAddress },
|
|
5928
|
-
{ suiKit: this.suiKit, address: this._address }
|
|
6394
|
+
{ suiKit: this.suiKit, address: this._address, cache: this.cache }
|
|
5929
6395
|
);
|
|
5930
6396
|
return scallopClient;
|
|
5931
6397
|
}
|
|
@@ -5939,7 +6405,8 @@ var Scallop = class {
|
|
|
5939
6405
|
await this._address.read();
|
|
5940
6406
|
const scallopQuery = new ScallopQuery(this.params, {
|
|
5941
6407
|
suiKit: this.suiKit,
|
|
5942
|
-
address: this._address
|
|
6408
|
+
address: this._address,
|
|
6409
|
+
cache: this.cache
|
|
5943
6410
|
});
|
|
5944
6411
|
return scallopQuery;
|
|
5945
6412
|
}
|
|
@@ -5949,7 +6416,9 @@ var Scallop = class {
|
|
|
5949
6416
|
* @return Scallop Indexer.
|
|
5950
6417
|
*/
|
|
5951
6418
|
async createScallopIndexer() {
|
|
5952
|
-
const scallopIndexer = new ScallopIndexer(
|
|
6419
|
+
const scallopIndexer = new ScallopIndexer(this.params, {
|
|
6420
|
+
cache: this.cache
|
|
6421
|
+
});
|
|
5953
6422
|
return scallopIndexer;
|
|
5954
6423
|
}
|
|
5955
6424
|
/**
|
|
@@ -5962,7 +6431,8 @@ var Scallop = class {
|
|
|
5962
6431
|
await this._address.read();
|
|
5963
6432
|
const scallopUtils = new ScallopUtils(this.params, {
|
|
5964
6433
|
suiKit: this.suiKit,
|
|
5965
|
-
address: this._address
|
|
6434
|
+
address: this._address,
|
|
6435
|
+
cache: this.cache
|
|
5966
6436
|
});
|
|
5967
6437
|
return scallopUtils;
|
|
5968
6438
|
}
|
|
@@ -5992,6 +6462,7 @@ var Scallop = class {
|
|
|
5992
6462
|
Scallop,
|
|
5993
6463
|
ScallopAddress,
|
|
5994
6464
|
ScallopBuilder,
|
|
6465
|
+
ScallopCache,
|
|
5995
6466
|
ScallopClient,
|
|
5996
6467
|
ScallopIndexer,
|
|
5997
6468
|
ScallopQuery,
|