@scallop-io/sui-scallop-sdk 0.45.0 → 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.
Files changed (43) hide show
  1. package/dist/builders/borrowIncentiveBuilder.d.ts +1 -1
  2. package/dist/builders/referralBuilder.d.ts +12 -0
  3. package/dist/constants/common.d.ts +1 -1
  4. package/dist/index.js +532 -278
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +586 -328
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/models/scallopCache.d.ts +6 -2
  9. package/dist/models/scallopQuery.d.ts +26 -28
  10. package/dist/queries/coreQuery.d.ts +3 -29
  11. package/dist/queries/index.d.ts +1 -0
  12. package/dist/queries/priceQuery.d.ts +3 -1
  13. package/dist/queries/referralQuery.d.ts +7 -0
  14. package/dist/queries/vescaQuery.d.ts +6 -2
  15. package/dist/types/address.d.ts +15 -0
  16. package/dist/types/builder/core.d.ts +2 -0
  17. package/dist/types/builder/index.d.ts +2 -1
  18. package/dist/types/builder/referral.d.ts +30 -0
  19. package/dist/types/builder/vesca.d.ts +1 -0
  20. package/package.json +7 -6
  21. package/src/builders/borrowIncentiveBuilder.ts +10 -19
  22. package/src/builders/coreBuilder.ts +54 -0
  23. package/src/builders/index.ts +5 -2
  24. package/src/builders/referralBuilder.ts +178 -0
  25. package/src/builders/vescaBuilder.ts +8 -6
  26. package/src/constants/common.ts +9 -2
  27. package/src/constants/vesca.ts +1 -3
  28. package/src/models/scallopAddress.ts +63 -19
  29. package/src/models/scallopCache.ts +42 -2
  30. package/src/models/scallopQuery.ts +40 -0
  31. package/src/models/scallopUtils.ts +35 -35
  32. package/src/queries/borrowIncentiveQuery.ts +2 -5
  33. package/src/queries/coreQuery.ts +33 -197
  34. package/src/queries/index.ts +1 -0
  35. package/src/queries/priceQuery.ts +48 -7
  36. package/src/queries/referralQuery.ts +27 -0
  37. package/src/queries/spoolQuery.ts +8 -12
  38. package/src/queries/vescaQuery.ts +93 -14
  39. package/src/types/address.ts +15 -0
  40. package/src/types/builder/core.ts +14 -0
  41. package/src/types/builder/index.ts +2 -0
  42. package/src/types/builder/referral.ts +51 -0
  43. package/src/types/builder/vesca.ts +1 -0
package/dist/index.mjs CHANGED
@@ -2,7 +2,10 @@
2
2
  var API_BASE_URL = "https://sui.api.scallop.io";
3
3
  var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
4
4
  var IS_VE_SCA_TEST = false;
5
- var ADDRESSES_ID = IS_VE_SCA_TEST ? "65fb07c39c845425d71d7b18" : "6601955b8b0024600a917079";
5
+ var ADDRESSES_ID = IS_VE_SCA_TEST ? (
6
+ // ? ('65fb07c39c845425d71d7b18' as const)
7
+ "65fb07c39c845425d71d7b18"
8
+ ) : "664dfe22898c36c159e28bc8";
6
9
  var PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
7
10
  var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
8
11
  var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
@@ -186,7 +189,7 @@ var voloCoinIds = {
186
189
 
187
190
  // src/constants/vesca.ts
188
191
  var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
189
- var MAX_LOCK_ROUNDS = IS_VE_SCA_TEST ? 9 : 1460;
192
+ var MAX_LOCK_ROUNDS = 1460;
190
193
  var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
191
194
  var MIN_INITIAL_LOCK_AMOUNT = 1e10;
192
195
  var MIN_TOP_UP_AMOUNT = 1e9;
@@ -196,7 +199,7 @@ import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
196
199
 
197
200
  // src/models/scallopCache.ts
198
201
  import { QueryClient } from "@tanstack/query-core";
199
- import { SuiTxBlock } from "@scallop-io/sui-kit";
202
+ import { SuiTxBlock, normalizeStructTag } from "@scallop-io/sui-kit";
200
203
 
201
204
  // src/constants/cache.ts
202
205
  var DEFAULT_CACHE_OPTIONS = {
@@ -383,6 +386,35 @@ var ScallopCache = class {
383
386
  }
384
387
  });
385
388
  }
389
+ async queryGetAllCoinBalances(owner) {
390
+ const queryKey = ["getAllCoinBalances", owner];
391
+ return this.queryClient.fetchQuery({
392
+ queryKey,
393
+ queryFn: async () => {
394
+ const allBalances = await this.suiKit.client().getAllBalances({ owner });
395
+ return allBalances.reduce(
396
+ (acc, coinBalance) => {
397
+ if (coinBalance.totalBalance !== "0") {
398
+ acc[normalizeStructTag(coinBalance.coinType)] = coinBalance.totalBalance;
399
+ }
400
+ return acc;
401
+ },
402
+ {}
403
+ );
404
+ }
405
+ });
406
+ }
407
+ async queryGetCoinBalance(input) {
408
+ const queryKey = ["getCoinBalance", input.owner, input.coinType];
409
+ return this.queryClient.fetchQuery({
410
+ queryKey,
411
+ queryFn: async () => {
412
+ if (!input.coinType)
413
+ return "0";
414
+ return (await this.queryGetAllCoinBalances(input.owner))[normalizeStructTag(input.coinType)] ?? "0";
415
+ }
416
+ });
417
+ }
386
418
  };
387
419
 
388
420
  // src/models/scallopAddress.ts
@@ -397,6 +429,45 @@ var EMPTY_ADDRESSES = {
397
429
  coinDecimalsRegistry: "",
398
430
  obligationAccessStore: "",
399
431
  coins: {
432
+ cetus: {
433
+ id: "",
434
+ metaData: "",
435
+ treasury: "",
436
+ oracle: {
437
+ supra: "",
438
+ switchboard: "",
439
+ pyth: {
440
+ feed: "",
441
+ feedObject: ""
442
+ }
443
+ }
444
+ },
445
+ apt: {
446
+ id: "",
447
+ metaData: "",
448
+ treasury: "",
449
+ oracle: {
450
+ supra: "",
451
+ switchboard: "",
452
+ pyth: {
453
+ feed: "",
454
+ feedObject: ""
455
+ }
456
+ }
457
+ },
458
+ sol: {
459
+ id: "",
460
+ metaData: "",
461
+ treasury: "",
462
+ oracle: {
463
+ supra: "",
464
+ switchboard: "",
465
+ pyth: {
466
+ feed: "",
467
+ feedObject: ""
468
+ }
469
+ }
470
+ },
400
471
  btc: {
401
472
  id: "",
402
473
  metaData: "",
@@ -518,15 +589,8 @@ var EMPTY_ADDRESSES = {
518
589
  oracles: {
519
590
  xOracle: "",
520
591
  xOracleCap: "",
521
- supra: {
522
- registry: "",
523
- registryCap: "",
524
- holder: ""
525
- },
526
- switchboard: {
527
- registry: "",
528
- registryCap: ""
529
- },
592
+ supra: { registry: "", registryCap: "", holder: "" },
593
+ switchboard: { registry: "", registryCap: "" },
530
594
  pyth: {
531
595
  registry: "",
532
596
  registryCap: "",
@@ -556,27 +620,25 @@ var EMPTY_ADDRESSES = {
556
620
  id: "",
557
621
  upgradeCap: ""
558
622
  },
559
- query: {
623
+ protocolWhitelist: {
560
624
  id: "",
561
625
  upgradeCap: ""
562
626
  },
563
- pyth: {
627
+ query: {
564
628
  id: "",
565
629
  upgradeCap: ""
566
630
  },
567
- switchboard: {
631
+ supra: { id: "", upgradeCap: "" },
632
+ pyth: {
568
633
  id: "",
569
634
  upgradeCap: ""
570
635
  },
636
+ switchboard: { id: "", upgradeCap: "" },
571
637
  xOracle: {
572
638
  id: "",
573
639
  upgradeCap: ""
574
640
  },
575
- // Deploy for faucet on testnet.
576
- testCoin: {
577
- id: "",
578
- upgradeCap: ""
579
- }
641
+ testCoin: { id: "", upgradeCap: "" }
580
642
  }
581
643
  },
582
644
  spool: {
@@ -616,24 +678,39 @@ var EMPTY_ADDRESSES = {
616
678
  id: "",
617
679
  rewardPoolId: ""
618
680
  }
619
- }
681
+ },
682
+ config: ""
620
683
  },
621
684
  borrowIncentive: {
622
685
  id: "",
623
686
  adminCap: "",
624
687
  object: "",
625
688
  query: "",
626
- config: "",
627
689
  incentivePools: "",
628
- incentiveAccounts: ""
690
+ incentiveAccounts: "",
691
+ config: ""
629
692
  },
630
693
  vesca: {
631
694
  id: "",
695
+ object: "",
632
696
  adminCap: "",
633
697
  tableId: "",
634
698
  table: "",
635
699
  treasury: "",
636
700
  config: ""
701
+ },
702
+ referral: {
703
+ id: "",
704
+ version: "",
705
+ object: "",
706
+ adminCap: "",
707
+ referralBindings: "",
708
+ bindingTableId: "",
709
+ referralRevenuePool: "",
710
+ revenueTableId: "",
711
+ referralTiers: "",
712
+ tiersTableId: "",
713
+ authorizedWitnessList: ""
637
714
  }
638
715
  };
639
716
  var ScallopAddress = class {
@@ -944,7 +1021,7 @@ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/util
944
1021
  import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
945
1022
 
946
1023
  // src/models/scallopUtils.ts
947
- import { SUI_TYPE_ARG, normalizeStructTag as normalizeStructTag5 } from "@mysten/sui.js/utils";
1024
+ import { SUI_TYPE_ARG, normalizeStructTag as normalizeStructTag6 } from "@mysten/sui.js/utils";
948
1025
  import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
949
1026
  import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
950
1027
 
@@ -952,8 +1029,7 @@ import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
952
1029
  import { SuiKit } from "@scallop-io/sui-kit";
953
1030
 
954
1031
  // src/queries/coreQuery.ts
955
- import { normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
956
- import BigNumber2 from "bignumber.js";
1032
+ import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
957
1033
 
958
1034
  // src/utils/builder.ts
959
1035
  var requireSender = (txBlock) => {
@@ -1052,10 +1128,10 @@ var checkVesca = (prevUnlockAtInSecondTimestamp) => {
1052
1128
 
1053
1129
  // src/utils/query.ts
1054
1130
  import BigNumber from "bignumber.js";
1055
- import { normalizeStructTag, parseStructTag } from "@mysten/sui.js/utils";
1131
+ import { normalizeStructTag as normalizeStructTag2, parseStructTag } from "@mysten/sui.js/utils";
1056
1132
  var parseOriginMarketPoolData = (originMarketPoolData) => {
1057
1133
  return {
1058
- coinType: normalizeStructTag(originMarketPoolData.type.name),
1134
+ coinType: normalizeStructTag2(originMarketPoolData.type.name),
1059
1135
  // Parse origin data required for basic calculations.
1060
1136
  maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
1061
1137
  borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
@@ -1150,7 +1226,7 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
1150
1226
  };
1151
1227
  var parseOriginMarketCollateralData = (originMarketCollateralData) => {
1152
1228
  return {
1153
- coinType: normalizeStructTag(originMarketCollateralData.type.name),
1229
+ coinType: normalizeStructTag2(originMarketCollateralData.type.name),
1154
1230
  collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / 2 ** 32,
1155
1231
  liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / 2 ** 32,
1156
1232
  liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / 2 ** 32,
@@ -1182,7 +1258,7 @@ var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
1182
1258
  };
1183
1259
  var parseOriginSpoolData = (originSpoolData) => {
1184
1260
  return {
1185
- stakeType: normalizeStructTag(originSpoolData.stakeType.fields.name),
1261
+ stakeType: normalizeStructTag2(originSpoolData.stakeType.fields.name),
1186
1262
  maxPoint: Number(originSpoolData.maxDistributedPoint),
1187
1263
  distributedPoint: Number(originSpoolData.distributedPoint),
1188
1264
  pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
@@ -1288,7 +1364,7 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
1288
1364
  };
1289
1365
  var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointData) => {
1290
1366
  return {
1291
- pointType: normalizeStructTag(
1367
+ pointType: normalizeStructTag2(
1292
1368
  originBorrowIncentivePoolPointData.point_type.name
1293
1369
  ),
1294
1370
  distributedPointPerPeriod: Number(
@@ -1307,7 +1383,7 @@ var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointDa
1307
1383
  };
1308
1384
  var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
1309
1385
  return {
1310
- poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
1386
+ poolType: normalizeStructTag2(originBorrowIncentivePoolData.pool_type.name),
1311
1387
  minStakes: Number(originBorrowIncentivePoolData.min_stakes),
1312
1388
  maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
1313
1389
  staked: Number(originBorrowIncentivePoolData.stakes),
@@ -1391,7 +1467,7 @@ var calculateBorrowIncentivePoolPointData = (pasredBorrowIncentinvePoolData, par
1391
1467
  };
1392
1468
  var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccountPoolPointData) => {
1393
1469
  return {
1394
- pointType: normalizeStructTag(
1470
+ pointType: normalizeStructTag2(
1395
1471
  originBorrowIncentiveAccountPoolPointData.point_type.name
1396
1472
  ),
1397
1473
  weightedAmount: Number(
@@ -1404,7 +1480,7 @@ var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccou
1404
1480
  };
1405
1481
  var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
1406
1482
  return {
1407
- poolType: normalizeStructTag(
1483
+ poolType: normalizeStructTag2(
1408
1484
  originBorrowIncentiveAccountData.pool_type.name
1409
1485
  ),
1410
1486
  debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
@@ -1501,6 +1577,7 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
1501
1577
  };
1502
1578
 
1503
1579
  // src/queries/coreQuery.ts
1580
+ import BigNumber2 from "bignumber.js";
1504
1581
  var queryMarket = async (query, indexer = false) => {
1505
1582
  const packageId = query.address.get("core.packages.query.id");
1506
1583
  const marketId = query.address.get("core.market");
@@ -1532,7 +1609,7 @@ var queryMarket = async (query, indexer = false) => {
1532
1609
  };
1533
1610
  }
1534
1611
  for (const pool of marketData.pools) {
1535
- const coinType = normalizeStructTag2(pool.type.name);
1612
+ const coinType = normalizeStructTag3(pool.type.name);
1536
1613
  const poolCoinName = query.utils.parseCoinNameFromType(coinType);
1537
1614
  const coinPrice = coinPrices[poolCoinName] ?? 0;
1538
1615
  if (!SUPPORT_POOLS.includes(poolCoinName)) {
@@ -1582,7 +1659,7 @@ var queryMarket = async (query, indexer = false) => {
1582
1659
  };
1583
1660
  }
1584
1661
  for (const collateral of marketData.collaterals) {
1585
- const coinType = normalizeStructTag2(collateral.type.name);
1662
+ const coinType = normalizeStructTag3(collateral.type.name);
1586
1663
  const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
1587
1664
  const coinPrice = coinPrices[collateralCoinName] ?? 0;
1588
1665
  if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
@@ -1974,182 +2051,54 @@ var queryObligation = async (query, obligationId) => {
1974
2051
  var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
1975
2052
  assetCoinNames = assetCoinNames || [...SUPPORT_POOLS];
1976
2053
  const owner = ownerAddress || query.suiKit.currentAddress();
1977
- const coinObjectsResponse = [];
1978
- let hasNextPage = false;
1979
- let nextCursor = null;
1980
- do {
1981
- const paginatedCoinObjectsResponse = await query.cache.queryGetOwnedObjects(
1982
- {
1983
- owner,
1984
- filter: {
1985
- MatchAny: assetCoinNames.map((assetCoinName) => {
1986
- const coinType = query.utils.parseCoinType(assetCoinName);
1987
- return { StructType: `0x2::coin::Coin<${coinType}>` };
1988
- })
1989
- },
1990
- options: {
1991
- showType: true,
1992
- showContent: true
1993
- },
1994
- cursor: nextCursor
1995
- }
1996
- );
1997
- coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
1998
- if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
1999
- hasNextPage = true;
2000
- nextCursor = paginatedCoinObjectsResponse.nextCursor;
2001
- } else {
2002
- hasNextPage = false;
2003
- }
2004
- } while (hasNextPage);
2005
- const coinAmounts = {};
2006
- const coinObjects = coinObjectsResponse.map((response) => {
2007
- return response.data;
2008
- }).filter(
2009
- (object) => object !== void 0 && object !== null
2054
+ const assetCoins2 = {};
2055
+ await Promise.allSettled(
2056
+ assetCoinNames.map(async (assetCoinName) => {
2057
+ const marketCoin = await getCoinAmount(query, assetCoinName, owner);
2058
+ assetCoins2[assetCoinName] = marketCoin;
2059
+ })
2010
2060
  );
2011
- for (const coinObject of coinObjects) {
2012
- const type = coinObject.type;
2013
- if (coinObject.content && "fields" in coinObject.content) {
2014
- const fields = coinObject.content.fields;
2015
- const poolCoinName = query.utils.parseCoinNameFromType(type);
2016
- if (poolCoinName) {
2017
- coinAmounts[poolCoinName] = BigNumber2(coinAmounts[poolCoinName] ?? 0).plus(fields.balance).toNumber();
2018
- }
2019
- }
2020
- }
2021
- return coinAmounts;
2061
+ return assetCoins2;
2022
2062
  };
2023
2063
  var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
2024
2064
  const owner = ownerAddress || query.suiKit.currentAddress();
2025
2065
  const coinType = query.utils.parseCoinType(assetCoinName);
2026
- const coinObjectsResponse = [];
2027
- let hasNextPage = false;
2028
- let nextCursor = null;
2029
- do {
2030
- const paginatedCoinObjectsResponse = await query.cache.queryGetOwnedObjects(
2031
- {
2032
- owner,
2033
- filter: { StructType: `0x2::coin::Coin<${coinType}>` },
2034
- options: {
2035
- showContent: true
2036
- },
2037
- cursor: nextCursor
2038
- }
2039
- );
2040
- coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
2041
- if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
2042
- hasNextPage = true;
2043
- nextCursor = paginatedCoinObjectsResponse.nextCursor;
2044
- } else {
2045
- hasNextPage = false;
2046
- }
2047
- } while (hasNextPage);
2048
- let coinAmount = 0;
2049
- const coinObjects = coinObjectsResponse.map((response) => {
2050
- return response.data;
2051
- }).filter(
2052
- (object) => object !== void 0 && object !== null
2053
- );
2054
- for (const coinObject of coinObjects) {
2055
- if (coinObject.content && "fields" in coinObject.content) {
2056
- const fields = coinObject.content.fields;
2057
- coinAmount = BigNumber2(coinAmount).plus(fields.balance).toNumber();
2058
- }
2059
- }
2060
- return coinAmount;
2066
+ const amount = await query.cache.queryGetCoinBalance({
2067
+ owner,
2068
+ coinType
2069
+ });
2070
+ return BigNumber2(amount).toNumber();
2061
2071
  };
2062
2072
  var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
2063
2073
  marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
2064
2074
  (poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
2065
2075
  );
2066
2076
  const owner = ownerAddress || query.suiKit.currentAddress();
2067
- const marketCoinObjectsResponse = [];
2068
- let hasNextPage = false;
2069
- let nextCursor = null;
2070
- do {
2071
- const paginatedMarketCoinObjectsResponse = await query.cache.queryGetOwnedObjects({
2072
- owner,
2073
- filter: {
2074
- MatchAny: marketCoinNames.map((marketCoinName) => {
2075
- const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
2076
- return { StructType: `0x2::coin::Coin<${marketCoinType}>` };
2077
- })
2078
- },
2079
- options: {
2080
- showType: true,
2081
- showContent: true
2082
- },
2083
- cursor: nextCursor
2084
- });
2085
- marketCoinObjectsResponse.push(...paginatedMarketCoinObjectsResponse.data);
2086
- if (paginatedMarketCoinObjectsResponse.hasNextPage && paginatedMarketCoinObjectsResponse.nextCursor) {
2087
- hasNextPage = true;
2088
- nextCursor = paginatedMarketCoinObjectsResponse.nextCursor;
2089
- } else {
2090
- hasNextPage = false;
2091
- }
2092
- } while (hasNextPage);
2093
- const marketCoinAmounts = {};
2094
- const marketCoinObjects = marketCoinObjectsResponse.map((response) => {
2095
- return response.data;
2096
- }).filter(
2097
- (object) => object !== void 0 && object !== null
2077
+ const marketCoins2 = {};
2078
+ Promise.allSettled(
2079
+ marketCoinNames.map(async (marketCoinName) => {
2080
+ const marketCoin = await getMarketCoinAmount(
2081
+ query,
2082
+ marketCoinName,
2083
+ owner
2084
+ );
2085
+ marketCoins2[marketCoinName] = marketCoin;
2086
+ })
2098
2087
  );
2099
- for (const marketCoinObject of marketCoinObjects) {
2100
- const marketCoinType = marketCoinObject.type;
2101
- if (marketCoinObject.content && "fields" in marketCoinObject.content) {
2102
- const fields = marketCoinObject.content.fields;
2103
- const marketCoinName = query.utils.parseCoinNameFromType(marketCoinType);
2104
- if (marketCoinName) {
2105
- marketCoinAmounts[marketCoinName] = BigNumber2(
2106
- marketCoinAmounts[marketCoinName] ?? 0
2107
- ).plus(fields.balance).toNumber();
2108
- }
2109
- }
2110
- }
2111
- return marketCoinAmounts;
2088
+ return marketCoins2;
2112
2089
  };
2113
2090
  var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
2114
2091
  const owner = ownerAddress || query.suiKit.currentAddress();
2115
2092
  const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
2116
- const marketCoinObjectsResponse = [];
2117
- let hasNextPage = false;
2118
- let nextCursor = null;
2119
- do {
2120
- const paginatedMarketCoinObjectsResponse = await query.cache.queryGetOwnedObjects({
2121
- owner,
2122
- filter: { StructType: `0x2::coin::Coin<${marketCoinType}>` },
2123
- options: {
2124
- showContent: true
2125
- },
2126
- cursor: nextCursor
2127
- });
2128
- marketCoinObjectsResponse.push(...paginatedMarketCoinObjectsResponse.data);
2129
- if (paginatedMarketCoinObjectsResponse.hasNextPage && paginatedMarketCoinObjectsResponse.nextCursor) {
2130
- hasNextPage = true;
2131
- nextCursor = paginatedMarketCoinObjectsResponse.nextCursor;
2132
- } else {
2133
- hasNextPage = false;
2134
- }
2135
- } while (hasNextPage);
2136
- let marketCoinAmount = 0;
2137
- const marketCoinObjects = marketCoinObjectsResponse.map((response) => {
2138
- return response.data;
2139
- }).filter(
2140
- (object) => object !== void 0 && object !== null
2141
- );
2142
- for (const marketCoinObject of marketCoinObjects) {
2143
- if (marketCoinObject.content && "fields" in marketCoinObject.content) {
2144
- const fields = marketCoinObject.content.fields;
2145
- marketCoinAmount = BigNumber2(marketCoinAmount).plus(fields.balance).toNumber();
2146
- }
2147
- }
2148
- return marketCoinAmount;
2093
+ const amount = await query.cache.queryGetCoinBalance({
2094
+ owner,
2095
+ coinType: marketCoinType
2096
+ });
2097
+ return BigNumber2(amount).toNumber();
2149
2098
  };
2150
2099
 
2151
2100
  // src/queries/spoolQuery.ts
2152
- import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
2101
+ import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
2153
2102
  var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2154
2103
  stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
2155
2104
  const stakeCoinNames = stakeMarketCoinNames.map(
@@ -2215,17 +2164,17 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
2215
2164
  spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName] || spoolIndexer.rewardCoinPrice;
2216
2165
  return spoolIndexer;
2217
2166
  }
2218
- const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
2219
- ids: [poolId, rewardPoolId],
2220
- options: {
2167
+ const spoolObjectResponse = await query.cache.queryGetObjects(
2168
+ [poolId, rewardPoolId],
2169
+ {
2221
2170
  showContent: true
2222
2171
  }
2223
- });
2224
- if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
2172
+ );
2173
+ if (marketPool && spoolObjectResponse[0] && spoolObjectResponse[1]) {
2225
2174
  const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
2226
2175
  coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
2227
- const spoolObject = spoolObjectResponse[0].data;
2228
- const rewardPoolObject = spoolObjectResponse[1].data;
2176
+ const spoolObject = spoolObjectResponse[0];
2177
+ const rewardPoolObject = spoolObjectResponse[1];
2229
2178
  if (spoolObject.content && "fields" in spoolObject.content) {
2230
2179
  const spoolFields = spoolObject.content.fields;
2231
2180
  const parsedSpoolData = parseOriginSpoolData({
@@ -2347,89 +2296,89 @@ var getStakeAccounts = async (query, ownerAddress) => {
2347
2296
  const index = Number(fields.index);
2348
2297
  const points = Number(fields.points);
2349
2298
  const totalPoints = Number(fields.total_points);
2350
- if (normalizeStructTag3(type) === stakeMarketCoinTypes.seth) {
2299
+ if (normalizeStructTag4(type) === stakeMarketCoinTypes.seth) {
2351
2300
  stakeAccounts.seth.push({
2352
2301
  id,
2353
- type: normalizeStructTag3(type),
2302
+ type: normalizeStructTag4(type),
2354
2303
  stakePoolId,
2355
- stakeType: normalizeStructTag3(stakeType),
2304
+ stakeType: normalizeStructTag4(stakeType),
2356
2305
  staked,
2357
2306
  index,
2358
2307
  points,
2359
2308
  totalPoints
2360
2309
  });
2361
- } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.ssui) {
2310
+ } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.ssui) {
2362
2311
  stakeAccounts.ssui.push({
2363
2312
  id,
2364
- type: normalizeStructTag3(type),
2313
+ type: normalizeStructTag4(type),
2365
2314
  stakePoolId,
2366
- stakeType: normalizeStructTag3(stakeType),
2315
+ stakeType: normalizeStructTag4(stakeType),
2367
2316
  staked,
2368
2317
  index,
2369
2318
  points,
2370
2319
  totalPoints
2371
2320
  });
2372
- } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.susdc) {
2321
+ } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.susdc) {
2373
2322
  stakeAccounts.susdc.push({
2374
2323
  id,
2375
- type: normalizeStructTag3(type),
2324
+ type: normalizeStructTag4(type),
2376
2325
  stakePoolId,
2377
- stakeType: normalizeStructTag3(stakeType),
2326
+ stakeType: normalizeStructTag4(stakeType),
2378
2327
  staked,
2379
2328
  index,
2380
2329
  points,
2381
2330
  totalPoints
2382
2331
  });
2383
- } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.susdt) {
2332
+ } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.susdt) {
2384
2333
  stakeAccounts.susdt.push({
2385
2334
  id,
2386
- type: normalizeStructTag3(type),
2335
+ type: normalizeStructTag4(type),
2387
2336
  stakePoolId,
2388
- stakeType: normalizeStructTag3(stakeType),
2337
+ stakeType: normalizeStructTag4(stakeType),
2389
2338
  staked,
2390
2339
  index,
2391
2340
  points,
2392
2341
  totalPoints
2393
2342
  });
2394
- } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.scetus) {
2343
+ } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.scetus) {
2395
2344
  stakeAccounts.scetus.push({
2396
2345
  id,
2397
- type: normalizeStructTag3(type),
2346
+ type: normalizeStructTag4(type),
2398
2347
  stakePoolId,
2399
- stakeType: normalizeStructTag3(stakeType),
2348
+ stakeType: normalizeStructTag4(stakeType),
2400
2349
  staked,
2401
2350
  index,
2402
2351
  points,
2403
2352
  totalPoints
2404
2353
  });
2405
- } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.safsui) {
2354
+ } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.safsui) {
2406
2355
  stakeAccounts.safsui.push({
2407
2356
  id,
2408
- type: normalizeStructTag3(type),
2357
+ type: normalizeStructTag4(type),
2409
2358
  stakePoolId,
2410
- stakeType: normalizeStructTag3(stakeType),
2359
+ stakeType: normalizeStructTag4(stakeType),
2411
2360
  staked,
2412
2361
  index,
2413
2362
  points,
2414
2363
  totalPoints
2415
2364
  });
2416
- } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.shasui) {
2365
+ } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.shasui) {
2417
2366
  stakeAccounts.shasui.push({
2418
2367
  id,
2419
- type: normalizeStructTag3(type),
2368
+ type: normalizeStructTag4(type),
2420
2369
  stakePoolId,
2421
- stakeType: normalizeStructTag3(stakeType),
2370
+ stakeType: normalizeStructTag4(stakeType),
2422
2371
  staked,
2423
2372
  index,
2424
2373
  points,
2425
2374
  totalPoints
2426
2375
  });
2427
- } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.svsui) {
2376
+ } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.svsui) {
2428
2377
  stakeAccounts.svsui.push({
2429
2378
  id,
2430
- type: normalizeStructTag3(type),
2379
+ type: normalizeStructTag4(type),
2431
2380
  stakePoolId,
2432
- stakeType: normalizeStructTag3(stakeType),
2381
+ stakeType: normalizeStructTag4(stakeType),
2433
2382
  staked,
2434
2383
  index,
2435
2384
  points,
@@ -2465,13 +2414,13 @@ var getStakePool = async (query, marketCoinName) => {
2465
2414
  const lastUpdate = Number(fields.last_update);
2466
2415
  stakePool = {
2467
2416
  id,
2468
- type: normalizeStructTag3(type),
2417
+ type: normalizeStructTag4(type),
2469
2418
  maxPoint,
2470
2419
  distributedPoint,
2471
2420
  pointPerPeriod,
2472
2421
  period,
2473
2422
  maxStake,
2474
- stakeType: normalizeStructTag3(stakeType),
2423
+ stakeType: normalizeStructTag4(stakeType),
2475
2424
  totalStaked,
2476
2425
  index,
2477
2426
  createdAt,
@@ -2508,7 +2457,7 @@ var getStakeRewardPool = async (query, marketCoinName) => {
2508
2457
  const claimedRewards = Number(rewardPoolFields.claimed_rewards);
2509
2458
  stakeRewardPool = {
2510
2459
  id,
2511
- type: normalizeStructTag3(type),
2460
+ type: normalizeStructTag4(type),
2512
2461
  stakePoolId,
2513
2462
  ratioNumerator,
2514
2463
  ratioDenominator,
@@ -2521,7 +2470,7 @@ var getStakeRewardPool = async (query, marketCoinName) => {
2521
2470
  };
2522
2471
 
2523
2472
  // src/queries/borrowIncentiveQuery.ts
2524
- import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
2473
+ import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui.js/utils";
2525
2474
  var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
2526
2475
  borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
2527
2476
  ...SUPPORT_BORROW_INCENTIVE_POOLS
@@ -2546,7 +2495,7 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
2546
2495
  ])
2547
2496
  ]
2548
2497
  );
2549
- const poolCoinType = normalizeStructTag4(pool.pool_type.name);
2498
+ const poolCoinType = normalizeStructTag5(pool.pool_type.name);
2550
2499
  const poolCoinName = query.utils.parseCoinNameFromType(
2551
2500
  poolCoinType
2552
2501
  );
@@ -2558,7 +2507,7 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
2558
2507
  for (const [coinName, poolPoint] of Object.entries(
2559
2508
  parsedBorrowIncentivePoolData.poolPoints
2560
2509
  )) {
2561
- const rewardCoinType = normalizeStructTag4(poolPoint.pointType);
2510
+ const rewardCoinType = normalizeStructTag5(poolPoint.pointType);
2562
2511
  const rewardCoinName = query.utils.parseCoinNameFromType(
2563
2512
  rewardCoinType
2564
2513
  );
@@ -2626,7 +2575,7 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
2626
2575
  var getBindedObligationId = async (query, veScaKeyId) => {
2627
2576
  const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
2628
2577
  const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2629
- const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : query.address.get("vesca.id");
2578
+ const veScaObjId = query.address.get("vesca.object");
2630
2579
  const client = query.suiKit.client();
2631
2580
  const incentivePoolsResponse = await client.getObject({
2632
2581
  id: incentivePoolsId,
@@ -2638,7 +2587,7 @@ var getBindedObligationId = async (query, veScaKeyId) => {
2638
2587
  return null;
2639
2588
  const incentivePoolFields = incentivePoolsResponse.data.content.fields;
2640
2589
  const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
2641
- const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
2590
+ const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaObjId}::ve_sca::VeScaKey>`;
2642
2591
  const veScaBindTableResponse = await client.getDynamicFieldObject({
2643
2592
  parentId: veScaBindTableId,
2644
2593
  name: {
@@ -2682,16 +2631,13 @@ var getBindedVeScaKey = async (query, obliationId) => {
2682
2631
  };
2683
2632
 
2684
2633
  // src/queries/priceQuery.ts
2685
- var getPythPrice = async (query, assetCoinName) => {
2634
+ var getPythPrice = async (query, assetCoinName, priceFeedObject) => {
2686
2635
  const pythFeedObjectId = query.address.get(
2687
2636
  `core.coins.${assetCoinName}.oracle.pyth.feedObject`
2688
2637
  );
2689
- const priceFeedObjectResponse = await query.cache.queryGetObject(
2690
- pythFeedObjectId,
2691
- { showContent: true }
2692
- );
2693
- if (priceFeedObjectResponse.data) {
2694
- const priceFeedPoolObject = priceFeedObjectResponse.data;
2638
+ priceFeedObject = priceFeedObject || (await query.cache.queryGetObject(pythFeedObjectId, { showContent: true })).data;
2639
+ if (priceFeedObject) {
2640
+ const priceFeedPoolObject = priceFeedObject;
2695
2641
  if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
2696
2642
  const fields = priceFeedPoolObject.content.fields;
2697
2643
  const expoMagnitude = Number(
@@ -2711,6 +2657,36 @@ var getPythPrice = async (query, assetCoinName) => {
2711
2657
  }
2712
2658
  return 0;
2713
2659
  };
2660
+ var getPythPrices = async (query, assetCoinNames) => {
2661
+ const seen = {};
2662
+ const pythFeedObjectIds = assetCoinNames.map((assetCoinName) => {
2663
+ const pythFeedObjectId = query.address.get(
2664
+ `core.coins.${assetCoinName}.oracle.pyth.feedObject`
2665
+ );
2666
+ if (seen[pythFeedObjectId])
2667
+ return null;
2668
+ seen[pythFeedObjectId] = true;
2669
+ return pythFeedObjectId;
2670
+ }).filter((item) => !!item);
2671
+ const priceFeedObjects = await query.cache.queryGetObjects(
2672
+ pythFeedObjectIds,
2673
+ {
2674
+ showContent: true
2675
+ }
2676
+ );
2677
+ return (await Promise.all(
2678
+ priceFeedObjects.map(async (priceFeedObject, idx) => ({
2679
+ coinName: assetCoinNames[idx],
2680
+ price: await getPythPrice(query, assetCoinNames[idx], priceFeedObject)
2681
+ }))
2682
+ )).reduce(
2683
+ (prev, curr) => {
2684
+ prev[curr.coinName] = curr.price;
2685
+ return prev;
2686
+ },
2687
+ {}
2688
+ );
2689
+ };
2714
2690
 
2715
2691
  // src/queries/portfolioQuery.ts
2716
2692
  import BigNumber3 from "bignumber.js";
@@ -3212,10 +3188,12 @@ var getTotalValueLocked = async (query, indexer = false) => {
3212
3188
 
3213
3189
  // src/queries/vescaQuery.ts
3214
3190
  import BigNumber4 from "bignumber.js";
3191
+ import { SUI_CLOCK_OBJECT_ID, SuiTxBlock as SuiTxBlock2 } from "@scallop-io/sui-kit";
3192
+ import { bcs } from "@mysten/sui.js/bcs";
3215
3193
  var getVescaKeys = async (query, ownerAddress) => {
3216
3194
  const owner = ownerAddress || query.suiKit.currentAddress();
3217
- const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : query.address.get("vesca.id");
3218
- const veScaKeyType = `${veScaPkgId}::ve_sca::VeScaKey`;
3195
+ const veScaObjId = query.address.get("vesca.object");
3196
+ const veScaKeyType = `${veScaObjId}::ve_sca::VeScaKey`;
3219
3197
  const keyObjectsResponse = [];
3220
3198
  let hasNextPage = false;
3221
3199
  let nextCursor = null;
@@ -3241,16 +3219,18 @@ var getVescaKeys = async (query, ownerAddress) => {
3241
3219
  var getVeScas = async (query, ownerAddress) => {
3242
3220
  const keyObjectDatas = await getVescaKeys(query, ownerAddress);
3243
3221
  const keyObjectId = keyObjectDatas.map((data) => data.objectId);
3244
- const veScas = [];
3245
- for (const keyId of keyObjectId) {
3222
+ const veScas = Array(keyObjectId.length).fill(null);
3223
+ const tasks = keyObjectId.map(async (keyId, idx) => {
3246
3224
  const veSca = await getVeSca(query, keyId);
3247
- if (veSca)
3248
- veScas.push(veSca);
3249
- }
3250
- return veScas;
3225
+ if (veSca) {
3226
+ veScas[idx] = veSca;
3227
+ }
3228
+ });
3229
+ await Promise.allSettled(tasks);
3230
+ return veScas.filter(Boolean).sort((a, b) => a.currentVeScaBalance - b.currentVeScaBalance);
3251
3231
  };
3252
3232
  var getVeSca = async (query, veScaKeyId, ownerAddress) => {
3253
- const tableId = IS_VE_SCA_TEST ? "0xc607241e4a679fe376d1170b2fbe07b64917bfe69100d4825241cda20039d4bd" : query.address.get(`vesca.tableId`);
3233
+ const tableId = query.address.get(`vesca.tableId`);
3254
3234
  veScaKeyId = veScaKeyId || (await getVescaKeys(query, ownerAddress))[0].objectId;
3255
3235
  let vesca = void 0;
3256
3236
  const veScaDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
@@ -3281,6 +3261,72 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
3281
3261
  }
3282
3262
  return vesca;
3283
3263
  };
3264
+ var getTotalVeScaTreasuryAmount = async (query) => {
3265
+ const veScaPkgId = query.address.get("vesca.id");
3266
+ const veScaConfig = query.address.get("vesca.config");
3267
+ const veScaTreasury = query.address.get("vesca.treasury");
3268
+ const refreshQueryTarget = `${veScaPkgId}::treasury::refresh`;
3269
+ const refreshArgs = [veScaConfig, veScaTreasury, SUI_CLOCK_OBJECT_ID];
3270
+ const veScaAmountQueryTarget = `${veScaPkgId}::treasury::total_ve_sca_amount`;
3271
+ const veScaAmountArgs = [veScaTreasury, SUI_CLOCK_OBJECT_ID];
3272
+ const resolvedRefreshArgs = await Promise.all(
3273
+ refreshArgs.map(async (arg) => {
3274
+ if (typeof arg === "string") {
3275
+ return (await query.cache.queryGetObject(arg, { showContent: true })).data;
3276
+ }
3277
+ return arg;
3278
+ })
3279
+ );
3280
+ const resolvedVeScaAmountArgs = await Promise.all(
3281
+ veScaAmountArgs.map(async (arg) => {
3282
+ if (typeof arg === "string") {
3283
+ return (await query.cache.queryGetObject(arg, { showContent: true })).data;
3284
+ }
3285
+ return arg;
3286
+ })
3287
+ );
3288
+ const txb = new SuiTxBlock2();
3289
+ txb.moveCall(refreshQueryTarget, resolvedRefreshArgs);
3290
+ txb.moveCall(veScaAmountQueryTarget, resolvedVeScaAmountArgs);
3291
+ const txBytes = await txb.txBlock.build({
3292
+ client: query.suiKit.client(),
3293
+ onlyTransactionKind: true,
3294
+ protocolConfig: await query.cache.getProtocolConfig()
3295
+ });
3296
+ const res = await query.cache.queryClient.fetchQuery({
3297
+ queryKey: [
3298
+ "getTotalVeScaTreasuryAmount",
3299
+ JSON.stringify([...refreshArgs, ...veScaAmountArgs])
3300
+ ],
3301
+ queryFn: async () => {
3302
+ return await query.suiKit.inspectTxn(txBytes);
3303
+ },
3304
+ staleTime: 8e3
3305
+ });
3306
+ const results = res.results;
3307
+ if (results && results[1].returnValues) {
3308
+ const value = Uint8Array.from(results[1].returnValues[0][0]);
3309
+ const type = results[1].returnValues[0][1];
3310
+ return bcs.de(type, value);
3311
+ }
3312
+ return "0";
3313
+ };
3314
+
3315
+ // src/queries/referralQuery.ts
3316
+ var queryVeScaKeyIdFromReferralBindings = async (query, refereeAddress) => {
3317
+ const referralBindingTableId = query.address.get("referral.bindingTableId");
3318
+ const referralBindResponse = await query.cache.queryGetDynamicFieldObject({
3319
+ parentId: referralBindingTableId,
3320
+ name: {
3321
+ type: "address",
3322
+ value: refereeAddress
3323
+ }
3324
+ });
3325
+ if (referralBindResponse.data?.content?.dataType !== "moveObject")
3326
+ return null;
3327
+ const fields = referralBindResponse.data.content.fields;
3328
+ return fields.value;
3329
+ };
3284
3330
 
3285
3331
  // src/models/scallopIndexer.ts
3286
3332
  import axios2 from "axios";
@@ -3600,6 +3646,15 @@ var ScallopQuery = class {
3600
3646
  async getPriceFromPyth(assetCoinName) {
3601
3647
  return await getPythPrice(this, assetCoinName);
3602
3648
  }
3649
+ /**
3650
+ * Get prices from pyth fee object.
3651
+ *
3652
+ * @param assetCoinNames - Array of supported asset coin names.
3653
+ * @return Array of asset coin prices.
3654
+ */
3655
+ async getPricesFromPyth(assetCoinNames) {
3656
+ return await getPythPrices(this, assetCoinNames);
3657
+ }
3603
3658
  /* ==================== Spool Query Methods ==================== */
3604
3659
  /**
3605
3660
  * Get spools data.
@@ -3798,6 +3853,29 @@ var ScallopQuery = class {
3798
3853
  async getTvl(indexer = false) {
3799
3854
  return await getTotalValueLocked(this, indexer);
3800
3855
  }
3856
+ /**
3857
+ * Get all veSca from walletAdddress
3858
+ * @param walletAddress
3859
+ * @returns array of veSca
3860
+ */
3861
+ async getVeScas(walletAddress) {
3862
+ return await getVeScas(this, walletAddress);
3863
+ }
3864
+ /**
3865
+ * Get total vesca treasury with movecall
3866
+ * @returns Promise<string | undefined>
3867
+ */
3868
+ async getTotalVeScaTreasuryAmount() {
3869
+ return await getTotalVeScaTreasuryAmount(this);
3870
+ }
3871
+ /**
3872
+ * Return binded veScaKeyId of walletAddress if exist
3873
+ * @param walletAddress
3874
+ * @returns veScaKeyId
3875
+ */
3876
+ async getVeScaKeyIdFromReferralBindings(walletAddress) {
3877
+ return await queryVeScaKeyIdFromReferralBindings(this, walletAddress);
3878
+ }
3801
3879
  /**
3802
3880
  * Get binded obligationId from a veScaKey if it exists.
3803
3881
  * @param veScaKey
@@ -3909,7 +3987,7 @@ var ScallopUtils = class {
3909
3987
  throw Error(`Coin ${coinName} is not supported`);
3910
3988
  }
3911
3989
  if (coinName === "sui")
3912
- return normalizeStructTag5(`${coinPackageId}::sui::SUI`);
3990
+ return normalizeStructTag6(`${coinPackageId}::sui::SUI`);
3913
3991
  const wormHolePckageIds = [
3914
3992
  this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc,
3915
3993
  this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt,
@@ -3942,7 +4020,7 @@ var ScallopUtils = class {
3942
4020
  return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
3943
4021
  }
3944
4022
  parseCoinNameFromType(coinType) {
3945
- coinType = normalizeStructTag5(coinType);
4023
+ coinType = normalizeStructTag6(coinType);
3946
4024
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
3947
4025
  const coinTypeMatch = coinType.match(coinTypeRegex);
3948
4026
  const isMarketCoinType = coinType.includes("reserve::MarketCoin");
@@ -4078,8 +4156,6 @@ var ScallopUtils = class {
4078
4156
  lackPricesCoinNames
4079
4157
  );
4080
4158
  for (const endpoint of endpoints) {
4081
- let hasFailRequest = false;
4082
- const pythConnection = new SuiPriceServiceConnection(endpoint);
4083
4159
  const priceIds = Array.from(failedRequests.values()).reduce(
4084
4160
  (acc, coinName) => {
4085
4161
  const priceId = this._address.get(
@@ -4090,43 +4166,46 @@ var ScallopUtils = class {
4090
4166
  },
4091
4167
  {}
4092
4168
  );
4093
- for (const [coinName, priceId] of Object.entries(priceIds)) {
4094
- try {
4095
- const feed = await this._cache.queryClient.fetchQuery({
4096
- queryKey: [priceId],
4097
- queryFn: async () => {
4098
- return await pythConnection.getLatestPriceFeeds([priceId]);
4099
- }
4100
- // staleTime: 15000,
4101
- });
4102
- if (feed) {
4103
- const data = parseDataFromPythPriceFeed(feed[0], this._address);
4104
- this._priceMap.set(coinName, {
4105
- price: data.price,
4106
- publishTime: data.publishTime
4169
+ await Promise.allSettled(
4170
+ Object.entries(priceIds).map(async ([coinName, priceId]) => {
4171
+ const pythConnection = new SuiPriceServiceConnection(endpoint);
4172
+ try {
4173
+ const feed = await this._cache.queryClient.fetchQuery({
4174
+ queryKey: [priceId],
4175
+ queryFn: async () => {
4176
+ return await pythConnection.getLatestPriceFeeds([priceId]);
4177
+ }
4107
4178
  });
4108
- coinPrices[coinName] = data.price;
4179
+ if (feed) {
4180
+ const data = parseDataFromPythPriceFeed(feed[0], this._address);
4181
+ this._priceMap.set(coinName, {
4182
+ price: data.price,
4183
+ publishTime: data.publishTime
4184
+ });
4185
+ coinPrices[coinName] = data.price;
4186
+ }
4187
+ failedRequests.delete(coinName);
4188
+ } catch (e) {
4189
+ console.warn(
4190
+ `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
4191
+ );
4109
4192
  }
4110
- failedRequests.delete(coinName);
4111
- } catch (e) {
4112
- console.warn(
4113
- `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
4114
- );
4115
- hasFailRequest = true;
4116
- }
4117
- }
4118
- if (!hasFailRequest)
4193
+ })
4194
+ );
4195
+ if (failedRequests.size === 0)
4119
4196
  break;
4120
4197
  }
4121
4198
  if (failedRequests.size > 0) {
4122
- for (const coinName of failedRequests.values()) {
4123
- const price = await this._query.getPriceFromPyth(coinName);
4124
- this._priceMap.set(coinName, {
4125
- price,
4126
- publishTime: Date.now()
4127
- });
4128
- coinPrices[coinName] = price;
4129
- }
4199
+ await Promise.allSettled(
4200
+ Array.from(failedRequests.values()).map(async (coinName) => {
4201
+ const price = await this._query.getPriceFromPyth(coinName);
4202
+ this._priceMap.set(coinName, {
4203
+ price,
4204
+ publishTime: Date.now()
4205
+ });
4206
+ coinPrices[coinName] = price;
4207
+ })
4208
+ );
4130
4209
  }
4131
4210
  }
4132
4211
  return coinPrices;
@@ -4191,11 +4270,11 @@ import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
4191
4270
 
4192
4271
  // src/builders/coreBuilder.ts
4193
4272
  import { TransactionBlock } from "@mysten/sui.js/transactions";
4194
- import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui.js/utils";
4273
+ import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID3 } from "@mysten/sui.js/utils";
4195
4274
  import { SuiTxBlock as SuiKitTxBlock } from "@scallop-io/sui-kit";
4196
4275
 
4197
4276
  // src/builders/oracle.ts
4198
- import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui.js/utils";
4277
+ import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui.js/utils";
4199
4278
  import {
4200
4279
  SuiPythClient,
4201
4280
  SuiPriceServiceConnection as SuiPriceServiceConnection2
@@ -4312,27 +4391,27 @@ var priceUpdateRequest = (txBlock, packageId, xOracleId, coinType) => {
4312
4391
  var confirmPriceUpdateRequest = (txBlock, packageId, xOracleId, request, coinType) => {
4313
4392
  const target = `${packageId}::x_oracle::confirm_price_update_request`;
4314
4393
  const typeArgs = [coinType];
4315
- txBlock.moveCall(target, [xOracleId, request, SUI_CLOCK_OBJECT_ID], typeArgs);
4394
+ txBlock.moveCall(target, [xOracleId, request, SUI_CLOCK_OBJECT_ID2], typeArgs);
4316
4395
  return txBlock;
4317
4396
  };
4318
4397
  var updateSupraPrice = (txBlock, packageId, request, holderId, registryId, coinType) => {
4319
4398
  txBlock.moveCall(
4320
4399
  `${packageId}::rule::set_price`,
4321
- [request, holderId, registryId, SUI_CLOCK_OBJECT_ID],
4400
+ [request, holderId, registryId, SUI_CLOCK_OBJECT_ID2],
4322
4401
  [coinType]
4323
4402
  );
4324
4403
  };
4325
4404
  var updateSwitchboardPrice = (txBlock, packageId, request, aggregatorId, registryId, coinType) => {
4326
4405
  txBlock.moveCall(
4327
4406
  `${packageId}::rule::set_price`,
4328
- [request, aggregatorId, registryId, SUI_CLOCK_OBJECT_ID],
4407
+ [request, aggregatorId, registryId, SUI_CLOCK_OBJECT_ID2],
4329
4408
  [coinType]
4330
4409
  );
4331
4410
  };
4332
4411
  var updatePythPrice = (txBlock, packageId, request, stateId, feedObjectId, registryId, coinType) => {
4333
4412
  txBlock.moveCall(
4334
4413
  `${packageId}::rule::set_price`,
4335
- [request, stateId, feedObjectId, registryId, SUI_CLOCK_OBJECT_ID],
4414
+ [request, stateId, feedObjectId, registryId, SUI_CLOCK_OBJECT_ID2],
4336
4415
  [coinType]
4337
4416
  );
4338
4417
  };
@@ -4365,6 +4444,8 @@ var generateCoreNormalMethod = ({
4365
4444
  coinDecimalsRegistry: builder.address.get("core.coinDecimalsRegistry"),
4366
4445
  xOracle: builder.address.get("core.oracles.xOracle")
4367
4446
  };
4447
+ const referralPkgId = builder.address.get("referral.id");
4448
+ const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
4368
4449
  return {
4369
4450
  openObligation: () => txBlock.moveCall(
4370
4451
  `${coreIds.protocolPkg}::open_obligation::open_obligation`,
@@ -4398,7 +4479,7 @@ var generateCoreNormalMethod = ({
4398
4479
  coreIds.coinDecimalsRegistry,
4399
4480
  amount,
4400
4481
  coreIds.xOracle,
4401
- SUI_CLOCK_OBJECT_ID2
4482
+ SUI_CLOCK_OBJECT_ID3
4402
4483
  ],
4403
4484
  [coinType]
4404
4485
  );
@@ -4407,7 +4488,7 @@ var generateCoreNormalMethod = ({
4407
4488
  const coinType = builder.utils.parseCoinType(poolCoinName);
4408
4489
  return txBlock.moveCall(
4409
4490
  `${coreIds.protocolPkg}::mint::mint`,
4410
- [coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID2],
4491
+ [coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID3],
4411
4492
  [coinType]
4412
4493
  );
4413
4494
  },
@@ -4415,7 +4496,7 @@ var generateCoreNormalMethod = ({
4415
4496
  const coinType = builder.utils.parseCoinType(poolCoinName);
4416
4497
  return txBlock.moveCall(
4417
4498
  `${coreIds.protocolPkg}::mint::mint_entry`,
4418
- [coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID2],
4499
+ [coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID3],
4419
4500
  [coinType]
4420
4501
  );
4421
4502
  },
@@ -4423,7 +4504,7 @@ var generateCoreNormalMethod = ({
4423
4504
  const coinType = builder.utils.parseCoinType(poolCoinName);
4424
4505
  return txBlock.moveCall(
4425
4506
  `${coreIds.protocolPkg}::redeem::redeem`,
4426
- [coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID2],
4507
+ [coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID3],
4427
4508
  [coinType]
4428
4509
  );
4429
4510
  },
@@ -4431,7 +4512,7 @@ var generateCoreNormalMethod = ({
4431
4512
  const coinType = builder.utils.parseCoinType(poolCoinName);
4432
4513
  return txBlock.moveCall(
4433
4514
  `${coreIds.protocolPkg}::redeem::redeem_entry`,
4434
- [coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID2],
4515
+ [coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID3],
4435
4516
  [coinType]
4436
4517
  );
4437
4518
  },
@@ -4447,11 +4528,29 @@ var generateCoreNormalMethod = ({
4447
4528
  coreIds.coinDecimalsRegistry,
4448
4529
  amount,
4449
4530
  coreIds.xOracle,
4450
- SUI_CLOCK_OBJECT_ID2
4531
+ SUI_CLOCK_OBJECT_ID3
4451
4532
  ],
4452
4533
  [coinType]
4453
4534
  );
4454
4535
  },
4536
+ borrowWithReferral: (obligation, obligationKey, borrowReferral, amount, poolCoinName) => {
4537
+ const coinType = builder.utils.parseCoinType(poolCoinName);
4538
+ return txBlock.moveCall(
4539
+ `${coreIds.protocolPkg}::borrow::borrow_with_referral`,
4540
+ [
4541
+ coreIds.version,
4542
+ obligation,
4543
+ obligationKey,
4544
+ coreIds.market,
4545
+ coreIds.coinDecimalsRegistry,
4546
+ borrowReferral,
4547
+ amount,
4548
+ coreIds.xOracle,
4549
+ SUI_CLOCK_OBJECT_ID3
4550
+ ],
4551
+ [coinType, referralWitnessType]
4552
+ );
4553
+ },
4455
4554
  borrowEntry: (obligation, obligationKey, amount, poolCoinName) => {
4456
4555
  const coinType = builder.utils.parseCoinType(poolCoinName);
4457
4556
  return txBlock.moveCall(
@@ -4464,7 +4563,7 @@ var generateCoreNormalMethod = ({
4464
4563
  coreIds.coinDecimalsRegistry,
4465
4564
  amount,
4466
4565
  coreIds.xOracle,
4467
- SUI_CLOCK_OBJECT_ID2
4566
+ SUI_CLOCK_OBJECT_ID3
4468
4567
  ],
4469
4568
  [coinType]
4470
4569
  );
@@ -4478,7 +4577,7 @@ var generateCoreNormalMethod = ({
4478
4577
  obligation,
4479
4578
  coreIds.market,
4480
4579
  coin,
4481
- SUI_CLOCK_OBJECT_ID2
4580
+ SUI_CLOCK_OBJECT_ID3
4482
4581
  ],
4483
4582
  [coinType]
4484
4583
  );
@@ -4592,6 +4691,26 @@ var generateCoreQuickMethod = ({
4592
4691
  poolCoinName
4593
4692
  );
4594
4693
  },
4694
+ borrowWithReferralQuick: async (amount, poolCoinName, borrowReferral, obligationId, obligationKey) => {
4695
+ const obligationInfo = await requireObligationInfo(
4696
+ builder,
4697
+ txBlock,
4698
+ obligationId,
4699
+ obligationKey
4700
+ );
4701
+ const obligationCoinNames = await builder.utils.getObligationCoinNames(
4702
+ obligationInfo.obligationId
4703
+ );
4704
+ const updateCoinNames = [...obligationCoinNames, poolCoinName];
4705
+ await updateOracles(builder, txBlock, updateCoinNames);
4706
+ return txBlock.borrowWithReferral(
4707
+ obligationInfo.obligationId,
4708
+ obligationInfo.obligationKey,
4709
+ borrowReferral,
4710
+ amount,
4711
+ poolCoinName
4712
+ );
4713
+ },
4595
4714
  repayQuick: async (amount, poolCoinName, obligationId) => {
4596
4715
  const sender = requireSender(txBlock);
4597
4716
  const obligationInfo = await requireObligationInfo(
@@ -4656,7 +4775,7 @@ var newCoreTxBlock = (builder, initTxBlock) => {
4656
4775
 
4657
4776
  // src/builders/spoolBuilder.ts
4658
4777
  import { TransactionBlock as TransactionBlock2 } from "@mysten/sui.js/transactions";
4659
- import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID3 } from "@mysten/sui.js/utils";
4778
+ import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID4 } from "@mysten/sui.js/utils";
4660
4779
  import { SuiTxBlock as SuiKitTxBlock2 } from "@scallop-io/sui-kit";
4661
4780
  var requireStakeAccountIds = async (...params) => {
4662
4781
  const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
@@ -4696,7 +4815,7 @@ var generateSpoolNormalMethod = ({
4696
4815
  );
4697
4816
  return txBlock.moveCall(
4698
4817
  `${spoolIds.spoolPkg}::user::new_spool_account`,
4699
- [stakePoolId, SUI_CLOCK_OBJECT_ID3],
4818
+ [stakePoolId, SUI_CLOCK_OBJECT_ID4],
4700
4819
  [marketCoinType]
4701
4820
  );
4702
4821
  },
@@ -4707,7 +4826,7 @@ var generateSpoolNormalMethod = ({
4707
4826
  );
4708
4827
  txBlock.moveCall(
4709
4828
  `${spoolIds.spoolPkg}::user::stake`,
4710
- [stakePoolId, stakeAccount, coin, SUI_CLOCK_OBJECT_ID3],
4829
+ [stakePoolId, stakeAccount, coin, SUI_CLOCK_OBJECT_ID4],
4711
4830
  [marketCoinType]
4712
4831
  );
4713
4832
  },
@@ -4718,7 +4837,7 @@ var generateSpoolNormalMethod = ({
4718
4837
  );
4719
4838
  return txBlock.moveCall(
4720
4839
  `${spoolIds.spoolPkg}::user::unstake`,
4721
- [stakePoolId, stakeAccount, amount, SUI_CLOCK_OBJECT_ID3],
4840
+ [stakePoolId, stakeAccount, amount, SUI_CLOCK_OBJECT_ID4],
4722
4841
  [marketCoinType]
4723
4842
  );
4724
4843
  },
@@ -4734,7 +4853,7 @@ var generateSpoolNormalMethod = ({
4734
4853
  const rewardCoinType = builder.utils.parseCoinType(rewardCoinName);
4735
4854
  return txBlock.moveCall(
4736
4855
  `${spoolIds.spoolPkg}::user::redeem_rewards`,
4737
- [stakePoolId, rewardPoolId, stakeAccount, SUI_CLOCK_OBJECT_ID3],
4856
+ [stakePoolId, rewardPoolId, stakeAccount, SUI_CLOCK_OBJECT_ID4],
4738
4857
  [marketCoinType, rewardCoinType]
4739
4858
  );
4740
4859
  }
@@ -4844,12 +4963,12 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
4844
4963
 
4845
4964
  // src/builders/borrowIncentiveBuilder.ts
4846
4965
  import { TransactionBlock as TransactionBlock4 } from "@mysten/sui.js/transactions";
4847
- import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID5 } from "@mysten/sui.js/utils";
4966
+ import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID6 } from "@mysten/sui.js/utils";
4848
4967
  import { SuiTxBlock as SuiKitTxBlock4 } from "@scallop-io/sui-kit";
4849
4968
 
4850
4969
  // src/builders/vescaBuilder.ts
4851
4970
  import {
4852
- SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID4,
4971
+ SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID5,
4853
4972
  TransactionBlock as TransactionBlock3,
4854
4973
  SuiTxBlock as SuiKitTxBlock3
4855
4974
  } from "@scallop-io/sui-kit";
@@ -4867,10 +4986,7 @@ var requireVeSca = async (...params) => {
4867
4986
  if (veScas.length === 0) {
4868
4987
  return void 0;
4869
4988
  }
4870
- return veScas.reduce(
4871
- (prev, acc) => acc.currentVeScaBalance > prev.currentVeScaBalance ? acc : prev,
4872
- veScas[0]
4873
- );
4989
+ return veScas[0];
4874
4990
  };
4875
4991
  var generateNormalVeScaMethod = ({
4876
4992
  builder,
@@ -4892,7 +5008,7 @@ var generateNormalVeScaMethod = ({
4892
5008
  veScaIds.treasury,
4893
5009
  scaCoin,
4894
5010
  unlockAtInSecondTimestamp,
4895
- SUI_CLOCK_OBJECT_ID4
5011
+ SUI_CLOCK_OBJECT_ID5
4896
5012
  ],
4897
5013
  []
4898
5014
  );
@@ -4906,7 +5022,7 @@ var generateNormalVeScaMethod = ({
4906
5022
  veScaIds.table,
4907
5023
  veScaIds.treasury,
4908
5024
  newUnlockAtInSecondTimestamp,
4909
- SUI_CLOCK_OBJECT_ID4
5025
+ SUI_CLOCK_OBJECT_ID5
4910
5026
  ],
4911
5027
  []
4912
5028
  );
@@ -4920,7 +5036,7 @@ var generateNormalVeScaMethod = ({
4920
5036
  veScaIds.table,
4921
5037
  veScaIds.treasury,
4922
5038
  scaCoin,
4923
- SUI_CLOCK_OBJECT_ID4
5039
+ SUI_CLOCK_OBJECT_ID5
4924
5040
  ],
4925
5041
  []
4926
5042
  );
@@ -4935,7 +5051,7 @@ var generateNormalVeScaMethod = ({
4935
5051
  veScaIds.treasury,
4936
5052
  scaCoin,
4937
5053
  newUnlockAtInSecondTimestamp,
4938
- SUI_CLOCK_OBJECT_ID4
5054
+ SUI_CLOCK_OBJECT_ID5
4939
5055
  ],
4940
5056
  []
4941
5057
  );
@@ -4948,10 +5064,17 @@ var generateNormalVeScaMethod = ({
4948
5064
  veScaKey,
4949
5065
  veScaIds.table,
4950
5066
  veScaIds.treasury,
4951
- SUI_CLOCK_OBJECT_ID4
5067
+ SUI_CLOCK_OBJECT_ID5
4952
5068
  ],
4953
5069
  []
4954
5070
  );
5071
+ },
5072
+ mintEmptyVeSca: () => {
5073
+ return txBlock.moveCall(
5074
+ `${veScaIds.pkgId}::ve_sca::mint_ve_sca_placeholder_key`,
5075
+ [veScaIds.config, veScaIds.table],
5076
+ []
5077
+ );
4955
5078
  }
4956
5079
  };
4957
5080
  };
@@ -5147,7 +5270,7 @@ var requireObligationInfo2 = async (...params) => {
5147
5270
  };
5148
5271
  var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5149
5272
  const borrowIncentiveIds = {
5150
- borrowIncentivePkg: IS_VE_SCA_TEST ? "0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246" : builder.address.get("borrowIncentive.id"),
5273
+ borrowIncentivePkg: builder.address.get("borrowIncentive.id"),
5151
5274
  query: builder.address.get("borrowIncentive.query"),
5152
5275
  config: builder.address.get("borrowIncentive.config"),
5153
5276
  incentivePools: builder.address.get("borrowIncentive.incentivePools"),
@@ -5172,7 +5295,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5172
5295
  obligationKey,
5173
5296
  obligationId,
5174
5297
  borrowIncentiveIds.obligationAccessStore,
5175
- SUI_CLOCK_OBJECT_ID5
5298
+ SUI_CLOCK_OBJECT_ID6
5176
5299
  ]
5177
5300
  );
5178
5301
  },
@@ -5190,7 +5313,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5190
5313
  veScaIds.treasury,
5191
5314
  veScaIds.table,
5192
5315
  veScaKey,
5193
- SUI_CLOCK_OBJECT_ID5
5316
+ SUI_CLOCK_OBJECT_ID6
5194
5317
  ],
5195
5318
  []
5196
5319
  );
@@ -5204,7 +5327,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5204
5327
  borrowIncentiveIds.incentiveAccounts,
5205
5328
  obligationKey,
5206
5329
  obligationId,
5207
- SUI_CLOCK_OBJECT_ID5
5330
+ SUI_CLOCK_OBJECT_ID6
5208
5331
  ]
5209
5332
  );
5210
5333
  },
@@ -5222,7 +5345,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5222
5345
  borrowIncentiveIds.incentiveAccounts,
5223
5346
  obligationKey,
5224
5347
  obligationId,
5225
- SUI_CLOCK_OBJECT_ID5
5348
+ SUI_CLOCK_OBJECT_ID6
5226
5349
  ],
5227
5350
  [rewardType]
5228
5351
  );
@@ -5236,7 +5359,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5236
5359
  borrowIncentiveIds.incentiveAccounts,
5237
5360
  obligation,
5238
5361
  veScaKey,
5239
- SUI_CLOCK_OBJECT_ID5
5362
+ SUI_CLOCK_OBJECT_ID6
5240
5363
  ]
5241
5364
  );
5242
5365
  }
@@ -5256,9 +5379,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5256
5379
  obligationKey
5257
5380
  );
5258
5381
  const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
5259
- (txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === (IS_VE_SCA_TEST ? `${"0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246"}::user::unstake` : `${builder.address.get(
5260
- "borrowIncentive.id"
5261
- )}::user::unstake`))
5382
+ (txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
5262
5383
  );
5263
5384
  if (!obligationLocked || unstakeObligationBeforeStake) {
5264
5385
  txBlock.stakeObligation(obligationArg, obligationtKeyArg);
@@ -5276,9 +5397,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5276
5397
  obligationKey
5277
5398
  );
5278
5399
  const unstakeObligationBeforeStake = !!txBlock.txBlock.blockData.transactions.find(
5279
- (txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === (IS_VE_SCA_TEST ? `${"0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246"}::user::unstake` : `${builder.address.get(
5280
- "borrowIncentive.id"
5281
- )}::user::unstake`))
5400
+ (txn) => txn.kind === "MoveCall" && (txn.target === `${OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake` || txn.target === `${builder.address.get("borrowIncentive.id")}::user::unstake`)
5282
5401
  );
5283
5402
  if (!obligationLocked || unstakeObligationBeforeStake) {
5284
5403
  const veSca = await requireVeSca(builder, txBlock, veScaKey);
@@ -5287,7 +5406,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5287
5406
  builder.query,
5288
5407
  veSca.keyId
5289
5408
  );
5290
- if (!bindedObligationId || bindedObligationId === obligationArg) {
5409
+ if ((!bindedObligationId || bindedObligationId === obligationArg) && veSca.currentVeScaBalance > 0) {
5291
5410
  txBlock.stakeObligationWithVesca(
5292
5411
  obligationArg,
5293
5412
  obligationtKeyArg,
@@ -5363,6 +5482,142 @@ var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
5363
5482
  });
5364
5483
  };
5365
5484
 
5485
+ // src/builders/referralBuilder.ts
5486
+ import {
5487
+ SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID7,
5488
+ SuiTxBlock as SuiKitTxBlock5,
5489
+ TransactionBlock as TransactionBlock5
5490
+ } from "@scallop-io/sui-kit";
5491
+ var generateReferralNormalMethod = ({
5492
+ builder,
5493
+ txBlock
5494
+ }) => {
5495
+ const referralIds = {
5496
+ referralPgkId: builder.address.get("referral.id"),
5497
+ referralBindings: builder.address.get("referral.referralBindings"),
5498
+ referralRevenuePool: builder.address.get("referral.referralRevenuePool"),
5499
+ authorizedWitnessList: builder.address.get(
5500
+ "referral.authorizedWitnessList"
5501
+ ),
5502
+ referralTiers: builder.address.get("referral.referralTiers"),
5503
+ version: builder.address.get("referral.version")
5504
+ };
5505
+ const veScaTable = builder.address.get("vesca.table");
5506
+ return {
5507
+ bindToReferral: (veScaKeyId) => {
5508
+ return txBlock.moveCall(
5509
+ `${referralIds.referralPgkId}::referral_bindings::bind_ve_sca_referrer`,
5510
+ [
5511
+ referralIds.referralBindings,
5512
+ txBlock.pure(veScaKeyId),
5513
+ veScaTable,
5514
+ SUI_CLOCK_OBJECT_ID7
5515
+ ],
5516
+ []
5517
+ );
5518
+ },
5519
+ claimReferralTicket: (poolCoinName) => {
5520
+ const coinType = builder.utils.parseCoinType(poolCoinName);
5521
+ return txBlock.moveCall(
5522
+ `${referralIds.referralPgkId}::scallop_referral_program::claim_ve_sca_referral_ticket`,
5523
+ [
5524
+ referralIds.version,
5525
+ veScaTable,
5526
+ referralIds.referralBindings,
5527
+ referralIds.authorizedWitnessList,
5528
+ referralIds.referralTiers,
5529
+ SUI_CLOCK_OBJECT_ID7
5530
+ ],
5531
+ [coinType]
5532
+ );
5533
+ },
5534
+ burnReferralTicket: (ticket, poolCoinName) => {
5535
+ const coinType = builder.utils.parseCoinType(poolCoinName);
5536
+ return txBlock.moveCall(
5537
+ `${referralIds.referralPgkId}::scallop_referral_program::burn_ve_sca_referral_ticket`,
5538
+ [
5539
+ referralIds.version,
5540
+ ticket,
5541
+ referralIds.referralRevenuePool,
5542
+ SUI_CLOCK_OBJECT_ID7
5543
+ ],
5544
+ [coinType]
5545
+ );
5546
+ },
5547
+ claimReferralRevenue: (veScaKey, poolCoinName) => {
5548
+ const coinType = builder.utils.parseCoinType(poolCoinName);
5549
+ return txBlock.moveCall(
5550
+ `${referralIds.referralPgkId}::referral_revenue_pool::claim_revenue_with_ve_sca_key`,
5551
+ [
5552
+ referralIds.version,
5553
+ referralIds.referralRevenuePool,
5554
+ veScaKey,
5555
+ SUI_CLOCK_OBJECT_ID7
5556
+ ],
5557
+ [coinType]
5558
+ );
5559
+ }
5560
+ };
5561
+ };
5562
+ var generateReferralQuickMethod = ({
5563
+ builder,
5564
+ txBlock
5565
+ }) => {
5566
+ return {
5567
+ claimReferralRevenueQuick: async (veScaKey, coinNames = [...SUPPORT_POOLS]) => {
5568
+ const sender = requireSender(txBlock);
5569
+ const objToTransfer = [];
5570
+ for (const coinName of coinNames) {
5571
+ if (coinName === "sui") {
5572
+ const rewardCoin = txBlock.claimReferralRevenue(veScaKey, coinName);
5573
+ objToTransfer.push(rewardCoin);
5574
+ } else {
5575
+ const coins = await builder.suiKit.suiInteractor.selectCoins(
5576
+ sender,
5577
+ Infinity,
5578
+ builder.utils.parseCoinType(coinName)
5579
+ );
5580
+ const rewardCoin = txBlock.claimReferralRevenue(veScaKey, coinName);
5581
+ if (coins.length > 0) {
5582
+ txBlock.mergeCoins(rewardCoin, coins);
5583
+ }
5584
+ objToTransfer.push(rewardCoin);
5585
+ }
5586
+ }
5587
+ if (objToTransfer.length > 0) {
5588
+ txBlock.transferObjects(objToTransfer, sender);
5589
+ }
5590
+ }
5591
+ };
5592
+ };
5593
+ var newReferralTxBlock = (builder, initTxBlock) => {
5594
+ const txBlock = initTxBlock instanceof TransactionBlock5 ? new SuiKitTxBlock5(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock5();
5595
+ const normalMethod = generateReferralNormalMethod({
5596
+ builder,
5597
+ txBlock
5598
+ });
5599
+ const normalTxBlock = new Proxy(txBlock, {
5600
+ get: (target, prop) => {
5601
+ if (prop in normalMethod) {
5602
+ return Reflect.get(normalMethod, prop);
5603
+ }
5604
+ return Reflect.get(target, prop);
5605
+ }
5606
+ });
5607
+ const quickMethod = generateReferralQuickMethod({
5608
+ builder,
5609
+ txBlock: normalTxBlock
5610
+ });
5611
+ return new Proxy(normalTxBlock, {
5612
+ get: (target, prop) => {
5613
+ if (prop in quickMethod) {
5614
+ return Reflect.get(quickMethod, prop);
5615
+ }
5616
+ return Reflect.get(target, prop);
5617
+ }
5618
+ });
5619
+ };
5620
+
5366
5621
  // src/builders/index.ts
5367
5622
  var newScallopTxBlock = (builder, initTxBlock) => {
5368
5623
  const vescaTxBlock = newVeScaTxBlock(builder, initTxBlock);
@@ -5370,7 +5625,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
5370
5625
  builder,
5371
5626
  vescaTxBlock
5372
5627
  );
5373
- const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
5628
+ const referralTxBlock = newReferralTxBlock(builder, borrowIncentiveTxBlock);
5629
+ const spoolTxBlock = newSpoolTxBlock(builder, referralTxBlock);
5374
5630
  const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
5375
5631
  return new Proxy(coreTxBlock, {
5376
5632
  get: (target, prop) => {
@@ -5378,6 +5634,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
5378
5634
  return Reflect.get(vescaTxBlock, prop);
5379
5635
  } else if (prop in borrowIncentiveTxBlock) {
5380
5636
  return Reflect.get(borrowIncentiveTxBlock, prop);
5637
+ } else if (prop in referralTxBlock) {
5638
+ return Reflect.get(referralTxBlock, prop);
5381
5639
  } else if (prop in spoolTxBlock) {
5382
5640
  return Reflect.get(spoolTxBlock, prop);
5383
5641
  }